6 ms·
What's new in Ruby 3.1?
- viraptor 5y agoI love how the idea of highlighting a specific part of the expression that can't be resolved jumped from one language to another within the last year or so and now the most common languages all support it. (I remember node and python getting it but now can't find that in the release notes - I didn't imagine it, right?)
- jhgb 5y ago> the idea of highlighting a specific part of the expression that can't be resolved jumped from one language to another within the last year CMUCL/SBCL must have supported this for decades.
- madeofpalk 5y agoI don't think Node does this. Maybe some test runners will do similar things to show expected vs actual in assertions? Or maybe I'm just so numb to it and I don't recall properly.
- bpeebles 5y agoPython, I believe, is getting this feature in 3.11, which is due out in October. But the first 3.11 alpha release got some news talking about it: https://docs.python.org/3.11/whatsnew/3.11.html https://docs.python.org/3.11/whatsnew/3.11.html
- asicsp 5y agoAs mentioned in further reading section, see also: Comprehensive Ruby 3.1 changelog: https://rubyreferences.github.io/rubychanges/3.1.html https://rubyreferences.github.io/rubychanges/3.1.html
- kayodelycaon 5y agoPicking up Ruby 3.0/3.1 after using 2.x for years is head spinning. Lots of new syntax to learn. A lot of the syntax feels like hacks because Ruby syntax is rather permissive and finding pattens that don’t collide increasingly difficult. Definitely has me a little grumbly, but I’ll get used to it eventually. Already loving _1.
- cassiogo 5y agoIm also not in love with the shorthand hash syntax, but besides `_1` I cant remember at the moment what new syntax 3.1 have that 2.0 dont. Pattern matching maybe? But now that I think about it, yeah, even looking only at pattern matching there is a lot of new syntax going on.
- gls2ro 5y agoFor me I think there are only two major things happening between 2.5 let's say and 3.0: - Keyword arguments - where there is no way around, you have to change them, upgrade gems... - Everything else is optional. Code that is written in 2.5 mostly runs on 3.0 Also, I recently updated a Rails app from 2.7 to 3.0 and no code change is required. I am asking as I am trying to use new syntax in my daily code so maybe I am missing something. What is the new syntax that you discovered in 3.0 that made your head spin?
- thr0wawayf00 5y ago> Keyword arguments - where there is no way around, you have to change them, upgrade gems... How does the keyword arguments change break old gems? I understood the new syntax to be optional in the case of not needing to repeat keys and values.
- deleted 5y ago[deleted]
- lewispb 5y agoThis explains the breaking change: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ https://www.ruby-lang.org/en/news/2019/12/12/separation-of-p...
- kayodelycaon 5y ago* RBS (Types) * single line method definitions (def ... = ...) * case...in * pin operator * rightward assignment (42 => int) * use of the above to destruct arrays and hashes ( x => { b: foo } ; foo #=> 2 )
- m12k 5y agoDoes anyone know if there's a tool out there similar to https://railsbump.org/ https://railsbump.org/ that would allow me to quickly check how many of the gems I depend on are compatible with ruby 3? I know ruby 3.0.x has been the recommended ruby version since rails 6.1, but I'm not sure if that means that a gem that is 6.1-compatible is necessarily also ruby 3 compatible (since rails 6.1 still supports ruby versions as old as 2.5.0)
- tibbon 5y agoRust has spoiled me. I truly wish this was just built into bundler. I should be able to just update the version, run bundle install, and know what is supported. Many dependencies have minimum, but not maximum versions specified. Most bugs have to be found at runtime (or via testing, which causes a runtime). Again, Rust has spoiled me because if cargo build compiles, then it’s almost certainly ok.
- ksec 5y ago>I truly wish this was just built into bundler. Interesting. Has anyone ever purposed this?
- judofyr 5y agoGems can already specify which version of Ruby they depend on: https://guides.rubygems.org/specification-reference/#required_ruby_version https://guides.rubygems.org/specification-reference/#require.... In practice you may not fully depend on it because people often write too permissive ranges (i.e. >= 2.7) and there has been some breaking changes between minor versions of Ruby 2.x so even if people write "~> 2.7" it may still be broken.
- buzzdenver 5y agoWhat is a compelling use case for omitting values in hashes or method calls? I would think that it just increases cognitive load for the code maintainer, and makes the parser more complex.
- dyeje 5y agoIt removes the boilerplate of repeating the variable name when it's the same as the hash key. It's an extremely popular syntax in the JavaScript world bleeding over into Ruby. Personally, I enjoy it because it feels more fluid.
- vvillena 5y agoRust has had this bit of syntax sugar for a while now, it is used for structs. I think it's nice syntax, because it's located in a place where there's no doubt about the meaning. Both Rust structs and Ruby hashes are defined in-language as key-value sets, so whenever there's just one element instead of a pair, it's clear what the meaning is.
- anentropic 5y agoOCaml has it too! (for records)
- hashhar 5y agoI have noticed that Ruby tends to move towards more magic which is true in this case. I don't see any benefits at all from this.
- gls2ro 5y agoI dont think a programming language can be _magic_ when talking about syntax. Syntax is something that one knows or dont know but no magic is there. It is like saying limit in math is magic. I could agree that we can evaluate if it is magic a library or a standard library. More to the point: In the Ruby apps that I saw so far and articles I read I get a different feeling: more and more the community is promoting clarity, explicitness, simplicity. I somehow feel that from Ruby 2 forward metaprogramming is seen as last resort. Almost no guideline promotes magic in Ruby code by default. More syntax is actually removing the need to do “magic tricks” with the language. It makes explicit in some cases some things that people were doing with DSLs. I feel that magic was more present in Ruby 1.9 for example than now even if syntax was more limited. I was solving a lot of things with metaprogramming, monkey patching, calling private attributes and more. Now I will not approve my own code from back then if I will see it in an MR.
- BiteCode_dev 5y agoI kinda dig the new mapping syntax: { a:, b: } #=> { a: 1, b: 2 } JS does it { a, b } and I find it very convenient, because if you code well, you usually have related things with the same name and repeating the name twice is just boilerplate. Because of the set syntax in Python, the JS syntax can't work, but the ruby one would be nice. Since Python keys can be anything, but usually are strings (and hence are quoted), I would probably invert the ":" though: { :a, :b }
- nicoburns 5y agoI really like the ruby syntax. JavaScript now has the problem that it can't make code blocks expressions because it's ambiguous with object literal shorthand.
- tln 5y agoJavaScript has labels, so objects have always been ambiguous with blocks
- BiteCode_dev 5y agoPython will never have block expression, given how limited lambda is already, so that's not a concern.
- lysecret 5y agothere is no way to achieve this in Python right? I miss this from js.
- BiteCode_dev 5y agoNope.
- dec0dedab0de 5y agoSo its a shortcut that if you pass a variable as a key with no value it automatically creates a key with the same name as the variable and assigns the value? That is kind of neat, but I tend to think of a bunch of {'a':a} as a bit of a code smell. Like maybe I should have used the hash/object/dict to begin with
- neoglow 5y ago> IRB now supports autocomplete, and even shows the documentation when you tab through the options. Oh this is pretty useful. How many times have I not wanted to learn about how to use a function. Showing the documentation when tabbing through the options can save me a lot of time browsing through the ruby docs. Looking forward to using this while working. Good to see Ruby is still moving forward :)
- cpursley 5y agoOther than existing code bases, what's the advantage of using Ruby for new projects these days when better tools exist? For example, Elixir - ergonomics of Ruby but cleaner functional approach, distributed and much faster for typical web apps.
- herbst 5y ago> better Better is a very personal thing :) I like the ecosystem of ruby, always did and never had a reason to change.
- cpursley 5y agoBetter is server bills that are 1/5 the cost, response times that are 3x faster and reduced complexity (no need for cache or background job servers). Don't get me wrong, I still really like and cut my teeth on Ruby, but there are better options for new projects now.
- weatherlite 5y agoThat's better performance, not better. Server bills is a pretty ridiculous metric to judge by; most of our server bills are due to the development kubernetes cluster (!), e.g our developers cost more in servers than our whole production setup. So what - should we go back to a monolith running locally then? Why use Elixir and not Go or Rust then if it's only performance you care about, Go has great concurrency and better general performance.
- cpursley 5y agoThat's why I said "other alternatives like Elixir". Go is one. Elixir syntax is comfortable (and productive) for Ruby devs and Phoenix for Rails folks. Use what you like.
- weatherlite 5y ago> Use what you like May I? Thanks!
- phendrenad2 5y agoWhat's new in Ruby 3.1? Needless, opaque syntax "features" that will just confuse new programmers even more.