Ruby
Ruby Next: Make old Ruby quack like a new one

Summarized using AI

Ruby Next: Make old Ruby quack like a new one

Vladimir Dementyev • November 18, 2019 • Nashville, TN

In this talk titled "Ruby Next: Make old Ruby quack like a new one," presented by Vladimir Dementyev at RubyConf 2019, the focus is on enabling developers to use new Ruby features without the need to immediately upgrade to the latest Ruby version. The key theme center around compatibility and leveraging modern syntax and features while still working in older Ruby environments, particularly Ruby 2.5.

Key Points Discussed:

  • Background: The speaker introduces Ruby Next, explaining the challenge developers face when they want to experiment with new features of Ruby, like pattern matching introduced in Ruby 2.7, while still using older versions like Ruby 2.5.
  • Upgrade Challenges: Many developers are hesitant to upgrade Ruby versions due to the significant costs in terms of compatibility and the minimal performance improvements gained from new releases.
  • Reflections on Ruby Development: Vladimir shares his experience as a library developer, noting the need to support various Ruby versions to accommodate users who may not have the latest Ruby installed.
  • Refinements: The talk emphasizes using refinements, a way to extend classes in a scoped manner without interfering with existing methods, as a method for backporting new features to older Ruby versions safely.
  • Transpilation: Ruby Next involves transpiling, which allows developers to write syntax from newer versions of Ruby that gets translated back to be compatible with older versions. This is achieved through libraries like 'ripper,' 'parser,' and 'ruby-ast'.
  • Community Commitment: The commitment of the Ruby Next community to thorough testing and validation for backporting techniques is highlighted, aiming to seamlessly integrate modern features into older Ruby environments.

Conclusion/Taking Away:

The Ruby Next initiative allows for a smoother transition to new Ruby functionalities without requiring immediate upgrades to the latest versions. This greatly enhances developer flexibility, enabling them to write cleaner, more modern Ruby code while maintaining support for older applications. The overall message encourages developers to participate in the movement towards a more versatile Ruby experience, where they can benefit from recent advances without being held back by version compatibility issues.

Ruby Next: Make old Ruby quack like a new one
Vladimir Dementyev • November 18, 2019 • Nashville, TN

RubyConf 2019 - Ruby Next: make old Ruby quack like a new one by Vladimir Dementyev

Ruby 2.7 is just around the corner. It will bring a lot of new features, including new syntax additions: pattern matching, numbered parameters.

That's good news. The bad news is that not many of us will be able to use these goodies right away: the upgrade cost blocks application developers; gem authors have to support older versions.

What if we were able to use Ruby Next features while running Ruby Current? Maybe, we can cast a metaprogramming spell for that? Yes, we can. And I'll show you how.

#confreaks #rubyconf2019

RubyConf 2019

00:00:12.830 Hello RubyConf! How are we doing? I hope you are all doing well. Welcome to my talk, where I will discuss Ruby, the programming language.
00:00:21.960 This talk is somewhat of a spin-off from the keynote presentation about upcoming Ruby features and the challenges they bring.
00:00:30.359 While I will touch on some of the features, my focus will be from the perspective of Ruby developers, rather than that of language designers or core team members making decisions.
00:00:49.530 Today, I will talk about "Ruby Next," which is a way to make old Ruby quack like a new one. Let me give you a brief overview of what I will cover.
00:01:00.239 Imagine you have an older version of Ruby, such as Ruby 2.5, and you want to try out the shiny new pattern matching syntax. It is likely that it will not work because Ruby 2.5 does not recognize this new syntax.
00:01:28.700 So, what is Ruby Next? In the context of this example, Ruby Next simply refers to a switch in the common module, which allows older Ruby versions to understand, recognize, and correctly evaluate newer features.
00:01:55.370 Now, let’s get to the official part of my talk. My name is Vladimir, and I am originally from Russia but currently reside in New York City.
00:02:01.290 I work for a consultancy agency called Evil Martians, which has agents all over the world, from San Francisco to Pampang, and right now I’m here in Nashville.
00:02:21.640 I'm the only one here, except for the clients. Alongside client work, we also do a lot of open source projects that you may have heard about.
00:02:34.400 As a Ruby developer, I maintain several Ruby gems. While they may not all be popular, many are familiar to some of you.
00:02:44.000 This brings me to the situation that led me to be here today discussing Ruby Next.
00:03:05.090 As a library developer, I need to support multiple Ruby versions since many users may not be using the most recent version. No one wants to use a library that does not support their version of Ruby.
00:03:30.440 Currently, I am migrating all of my libraries to support at least Ruby 2.5 because Ruby 2.4 is officially dead.
00:03:45.470 However, I want to use features from Ruby 2.7. The problem is that I can’t utilize those new features because I need to maintain compatibility.
00:04:01.489 Now I want to ask a question: how many of you here are gem authors? Okay, now how many of you are application developers? It seems most of you are application developers.
00:04:23.160 Even if you develop applications, it doesn't mean you can upgrade your Ruby version right away. According to JetBrains, many Ruby developers are still using previous versions.
00:04:35.490 Many developers are hesitant to switch to a new Ruby version because the cost of upgrading can be steep. It’s not as simple as just changing the Ruby version and updating the repository.
00:05:03.539 The effort required for an upgrade is substantial, and the performance improvements are often minimal.
00:05:11.210 While every Ruby release introduces performance improvements, they are often not significant enough to compel developers to upgrade.
00:05:39.780 Furthermore, the excitement for new features should be a reason to upgrade, but until Ruby 2.7, there hadn't been that much appeal in terms of shiny new features.
00:05:57.750 Two years ago, with Ruby 2.5, a feature caught my attention: the `defined?` operator. Initially, I was skeptical about its utility, but my perspective changed once I started using it in practice.
00:06:23.629 This led me to explore ways to backport new features to older versions of Ruby without conflicting with existing methods in libraries. I turned to refinements, a safe way to extend classes and modules without risking method collisions.
00:07:09.029 Refinements are a way to monkey-patch Ruby classes in a scoped manner so that new methods are only available within specific contexts.
00:07:35.550 This method of backporting is safer compared to traditional monkey patching. So, I decided to use refinements to bring new methods to older Ruby versions without introducing conflicts.
00:08:06.869 Who here is familiar with how refinements work? They were introduced in Ruby 2.0 but were considered experimental. Many developers were apprehensive about using them due to their initial label.
00:08:43.240 However, refinements have matured over the years, and by Ruby 2.5, they became a more consistent feature that we can rely on.
00:09:00.790 Refinements allow you to create a scoped definition of methods, meaning the core method lookup behavior is adjusted lexically.
00:09:39.160 This means that the scope of any added methods is limited to where you activated that refinement.
00:10:02.620 This makes refinements a powerful tool when it comes to extending Ruby's features safely.
00:10:20.590 I decided to leverage refinements to backport new APIs to older Ruby versions.
00:10:38.240 For example, while working with Ruby 2.5, I started to integrate a collection of useful methods that existed in newer Ruby versions.
00:11:29.000 One important aspect of Ruby Next is that it enables usage of modern Ruby features in older applications seamlessly.
00:12:04.250 Next, I want to delve into the core concept of Ruby Next and how it combines universal refinements for backporting APIs along with a transpiler for new syntax features.
00:12:31.020 Transpiling is the process of compiling source code from one version to another, allowing developers to write code in the latest versions while still supporting older Ruby implementations.
00:12:49.950 An example of transpiles in action is how we translate newer Ruby syntax, like pattern matching or numbered parameters, back to older versions of Ruby.
00:13:38.130 In doing so, we parse the source code, modify the abstract syntax tree, and regenerate the corresponding Ruby code for compatibility.
00:14:17.500 We get to leverage existing libraries like 'ripper,' 'parser,' and 'ruby-ast' to assist with code transformations, offering a powerful way to maintain compatibility with new features.
00:15:00.320 As we move towards the future, Ruby Next aims to further integrate methods to support syntax that is currently experimental, while offering existing functionality to older Ruby developers.
00:15:40.370 Furthermore, ensuring that Ruby Next is compatible with the various existing Ruby frameworks remains a crucial part of the development process.
00:16:20.550 The idea is to create the next evolution of Ruby without users needing to worry about version compatibility.
00:16:37.080 Overall, the community behind Ruby Next is committed to providing thorough testing and validation for our backporting techniques.
00:17:14.890 By combining modern syntaxes and techniques, Ruby Next can help developers write cleaner code, maintain compatibility across versions, and truly leverage the best of Ruby.
00:17:49.980 In conclusion, Ruby Next is a pivotal tool that ensures old Ruby can indeed quack like a new one, enabling adaptability and providing a streamlined transition towards newer features and syntaxes.
00:18:20.490 So don’t be afraid; join the journey into Ruby Next, where modern functionalities can be used even in older implementations.
00:18:36.400 Thank you for your time, and I am open to your questions!
Explore all talks recorded at RubyConf 2019
+88