At the beginning of each year, the technology articles seem to focus on one topic only - trying to answer the question ‘Is *insert the technology here* still relevant? Ruby on Rails is no different. You might be surprised that even though it is over 15 years old it is not slowing down and still has a great group of supporters and newcomers.
2020 has brought a lot of changes, also to the Ruby community. Ruby 3.0 was introduced at the end of December bringing changes in performance and concurrency. Want to know more about those changes? How is it different from its predecessor? This article will sum up everything there is to know about the latest Ruby update.
Differences between Ruby and Ruby on Rails
Are you aware that there are probably some people who do not know the differences between Ruby and Ruby on Rails? Let me briefly explain to get everybody on the same page.
Ruby is an object-oriented scripting language. It is open-source, free and easily available. It has a very clear syntax making it easy to write and understand. Ruby is known for its balance between power and simplicity, which means programs written in it are usually scalable and easy to maintain. What is more, Ruby has features like dynamic typing and duck typing, flexible syntax, exception handling, variable scope, overloading etc.
On the other side, we have Ruby on Rails. It is a web application framework based on the model view controller (MVC) architecture. This means data is separated from user interfaces. To get it more easily differentiated, Ruby on Rails is referred to as simply Rails.
Ruby on Rails follows concepts like Don’t repeat yourself (DRY) and Convention over configuration (COC).
Why are we using RoR?
When talking about Ruby programming language, it is almost impossible not to mention Ruby on Rails. It is quite possible, people would not be aware of the benefits of Ruby if it were not for Rails. However, we should keep in mind that even without RoR, Ruby has quite a lot of advantages like versatility, freedom, user-friendliness, readability and compliance. When combined with Rails, it gets even better. Let’s mention a few of the pros:
- expressiveness - Rails team achieved a good balance with DSL making it easy to understand
- pragmatism - often mentioned when talking about Rails and is tied with Rails at the lowest level possible
- maturity - RoR has been around since 2005 and has been used by companies like Github or Shopify
- simplicity - Rails has been designed to build web software that can be used by real businesses
- community - maintainers still care and want people to use RoR so help is available at any time
- time-to-market - Rails is an amazing choice for MVP development since it supports fast coding
- security - RoR and Ruby are perfect for data-sensitive applications for healthcare, financial or eCommerce industries
- cross-platform - code written with Ruby can be run on various devices and operating systems
- cost-efficiency - you need to pay less for the development thanks to many free tools and libraries available
Changes in Ruby 3.0
After establishing that Ruby is still relevant and explaining its advantages, we can move on to discussing the changes Ruby 3.0 introduced.
Ruby 3.0 is 3 times faster than Ruby 2! Optcarrot benchmark measured thread performance, based on NES’s game emulation workload and came back with an amazing score, in comparison to the previous version of the language.
Many improvements were introduced in MJIT. Ruby 3.0 gives performance improvements in limited workloads, like Optcarrot or AI Rubykon and in applications that call a few methods many times. Although Ruby 3.0 decreases the size of JIT-ed code it is still not fully ready for optimizing workloads - further improvements are anticipated in the Ruby 3.1 release.
Concurrency is very important in the multi-core ages. Thanks to Ractor (an Actor-model like concurrent abstraction), together with Async Fiber, Ruby becomes a real concurrent language. Ractor enables parallel execution without safety concerns since it can share normal objects. Communication between Ractors is supported by exchanging messages.
Note: Ractor introduces several restrictions to Ruby’s syntax in order to limit the sharing of objects.
Introduced for intercepting blocking operations, which allows light-weight concurrency without changing the existing code.
- Mutex#lock, Mutex#unlock, Mutex#sleep
- Queue#pop, SizedQueue#push
- IO#wait, IO#read, IO#write, and related methods (e.g. #wait_readable, #gets, #puts, and so on).
Note: IO#select is not supported.
Typing (Static Analysis)
Ruby goes to the future with static type checking, but without type declaration, using abstract interpretation. RBS and TypeProf are the first steps to the future.
RBS is a language used to describe the types of Ruby programs. Type checkers and tools supporting RBS will understand Ruby programs much better thanks to RBS definitions. The main goal of RBS is to support common patterns in Ruby programs and allow writing advanced types including union types, method overloading and generics. It also supports duck typing with interface types.
Ruby 3.0 ships with the
rbs gem, which allows parsing and processing type definitions written in RBS.
TypeProf is a type analysis tool bundled in the Ruby package and serves as a kind of type inference. It reads plain Ruby code, analyzes what methods are defined and how they are used to later generate a prototype of type signature in RBS format.
Other notable changes
You might be thinking that this is all there is, but I would like to mention a few other things that changed with Ruby 3.0.
One-line pattern matching redesigned
- => is added. It can be used like a rightward assignment
- in is changed to return true or false
Find patterns added
Endless method definition added
def square(x) = x \* x
- pasting long code to IRB is 53 times faster than in the version bundled with Ruby 2.7.0
- measure command has been added to IRB. It allows simple execution time measurement
- Keyword arguments are separated from other arguments
- Pattern matching (case/in) is no longer experimental
- The order of backtraces had been reversed with Ruby 2.5; this change has been reverted. Now backtraces behave like in Ruby 2.4
- Some standard libraries updated (RubyGems, Bundler, IRB, JSON, CSV etc.)
Summary: Is Ruby on Rails dead in 2021?
The good old Ruby and Ruby on Rails are definitely not dead. They are still a must for many projects, including those owned by giants like Amazon, Slideshare or Airbnb. Rails still has the most popular communities on GitHub with over 4k contributors. It remains functional, reliable while being relatively easy to learn and understand.
Ruby is perfect for developing SaaS solutions, MVPs and cross-platform applications. It is a practical language suited for solving specific business tasks. Additionally, Ruby on Rails is also thriving as it remains one of the most popular web development frameworks being fast and efficient for both web and mobile solutions.
If you are looking for an experienced Ruby and Ruby on Rails team that can handle your development, fill out the contact form to schedule a call with our experts. We can provide you with a fully-fledged team with designers and QA engineers to make your project the best it can be.