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:
I 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.
It's not just because of the set syntax; it's also because Python dicts don't treat their keys as symbols, but rather evaluate them as expressions, whereas JS evaluates keys as symbols by default and requires `{[key]: val}` to evaluate them. So in Python you'd have to do something funky where `{a: a}` is `{value_of_a: value_of_a}`, but, say, `{a:}` is `{"a": value_of_a}`.
So 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
Does anyone know if there's a tool out there similar to 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)
Rust 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.
Im 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.
I 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?)
> 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.
What 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.
Rust 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.
It 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.
Other 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.
Elixir certainly has its use case, but so does Ruby. Things like the huge amount of available gems and a big community, especially combined with a proven framework like Rails really makes it easy to build applications.
Elixir is well suited for a lot of things Ruby is but also has some shortcomings. For instance, the albeit growing community and available libraries is just not on the same level as Ruby. Furthermore the amount of available engineers knowing elixir can be a problem when hiring (ofcourse these can be trained internally) but in general hiring will be a tad bit harder.
Whilst I agree with you on the technical side (language is cleaner and obviously more performant) I do not agree on the statement dat Elixir is a better tool, as with a lot of things in software it depends.
I've had professional gigs spanning Ruby, Elixir, JS, C#, F#, and Python. I've found that Ruby is the most enjoyable to work with and has the easiest learning curve. It's a language that doesn't feel pretentious or dysfunctional, and most importantly of all, I can get shit done with it.
[+] [-] BiteCode_dev|4 years ago|reply
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:
[+] [-] nicoburns|4 years ago|reply
[+] [-] bobbylarrybobby|4 years ago|reply
[+] [-] dec0dedab0de|4 years ago|reply
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
[+] [-] lysecret|4 years ago|reply
[+] [-] m12k|4 years ago|reply
[+] [-] tibbon|4 years ago|reply
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.
[+] [-] kayodelycaon|4 years ago|reply
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.
[+] [-] gls2ro|4 years ago|reply
- 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?
[+] [-] cassiogo|4 years ago|reply
But now that I think about it, yeah, even looking only at pattern matching there is a lot of new syntax going on.
[+] [-] viraptor|4 years ago|reply
(I remember node and python getting it but now can't find that in the release notes - I didn't imagine it, right?)
[+] [-] bpeebles|4 years ago|reply
https://docs.python.org/3.11/whatsnew/3.11.html
[+] [-] jhgb|4 years ago|reply
CMUCL/SBCL must have supported this for decades.
[+] [-] madeofpalk|4 years ago|reply
Or maybe I'm just so numb to it and I don't recall properly.
[+] [-] asicsp|4 years ago|reply
Comprehensive Ruby 3.1 changelog: https://rubyreferences.github.io/rubychanges/3.1.html
[+] [-] neoglow|4 years ago|reply
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 :)
[+] [-] buzzdenver|4 years ago|reply
[+] [-] vvillena|4 years ago|reply
[+] [-] gls2ro|4 years ago|reply
[+] [-] dyeje|4 years ago|reply
[+] [-] fourseventy|4 years ago|reply
[+] [-] hashhar|4 years ago|reply
I don't see any benefits at all from this.
[+] [-] phendrenad2|4 years ago|reply
[+] [-] cpursley|4 years ago|reply
[+] [-] silentprog|4 years ago|reply
Elixir is well suited for a lot of things Ruby is but also has some shortcomings. For instance, the albeit growing community and available libraries is just not on the same level as Ruby. Furthermore the amount of available engineers knowing elixir can be a problem when hiring (ofcourse these can be trained internally) but in general hiring will be a tad bit harder.
Whilst I agree with you on the technical side (language is cleaner and obviously more performant) I do not agree on the statement dat Elixir is a better tool, as with a lot of things in software it depends.
[+] [-] Nuzzerino|4 years ago|reply
[+] [-] herbst|4 years ago|reply
Better is a very personal thing :) I like the ecosystem of ruby, always did and never had a reason to change.