Live data from Hacker News

New Features in Ruby 2.4

blog.blockscore.com

21–30 of 76 posts

Re: New Features in Ruby 2.4

#21
post #2

Some of these are pretty amazing, like the `digits` method and the new OptionParser functionality (which seems to be a sort of standard library equivalent to doctopt!). That being said, I can't help but shake my head at the section about "multiple assignment of conditionals: "You can now assign multiple variables within a conditional...You probably shouldn’t do that though." Am I alone and thinking that it's a little…

> Am I alone and thinking that it's a little bit hypocritical to specifically add functionality to your language if you don't want people to use it?

It's just a change to make the language more consistent. `a, b = something` already worked as an expression in most places, so it makes sense that it should be allowed on `if` conditions too. Before 2.4:

  > if (a, b = nil) then :foo else :bar end
  SyntaxError: (eval):2: multiple assignment in conditional
So instead of having that special syntax error, and probably needing a justification for it, Ruby 2.4 makes `a, b = something` a valid expression there and removes an edge case.

That you probably shouldn't use multiple assignment on an `if` condition is a separate issue. It's just a preference, and it follows the same logic of avoiding assignments on conditional expressions in general.

Re: New Features in Ruby 2.4

#22
post #2

Some of these are pretty amazing, like the `digits` method and the new OptionParser functionality (which seems to be a sort of standard library equivalent to doctopt!). That being said, I can't help but shake my head at the section about "multiple assignment of conditionals: "You can now assign multiple variables within a conditional...You probably shouldn’t do that though." Am I alone and thinking that it's a little…

It is usually not a great idea, but there are some patterns where it produces code that is a lot nicer than not. In practice, this will allow stuff like

    while x, y = foo.pop
      ..
    end
which without the mass assignment will require duplication of the assignment line.

Re: New Features in Ruby 2.4

#23
post #13

These improvements feel like amateur hour. No leadership no roadmap no goals.

Roadmap towards what? World domination? Ruby is a mature language, and this is a point release with some incremental improvements.

Go to Perl 6 and Python 3 for leadership, roadmap and goals. As if those worked out well for them...

Re: New Features in Ruby 2.4

#24
post #20

Ruby 2.4 adds a new #match? method for regular expressions which is three times faster than any Regexp method in Ruby 2.3: Why does Ruby have 4 different regexp match functions? Regexp#match?: 2630002.5 i/s Regexp#===: 872217.5 i/s - 3.02x slower Regexp#=~: 859713.0 i/s - 3.06x slower Regexp#match: 539361.3 i/s - 4.88x slower

So there is choice of course. match returns match data, and sets the $~ variable === returns true or false, setting the $~ variable =~ returns integer (position) or nil, setting $~ The newest one match? returns a boolean, not setting $~

Also, === is the method used in case statement matching.

Re: New Features in Ruby 2.4

#25

> If you are calling #sum on an array of non-integers then you need to provide your own initial value Why? This doesn't seem necessary, but, more importantly, would be inconsistent with #inject's behaviour (if enforced). ---- http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-inje... : If you do not explicitly specify an initial value for memo, then the first element of collection is used as the initial value of…

I assume (but don't know) that this is an attempt to avoid returning `nil` for empty collections: `[].inject(:+)` is `nil`, but `[].sum` is `0`. Forcing the use of the additive identity every time, rather than starting with the first element of the collection, is a good way of setting people up to get the correct behaviour on empty collections, even if they don't test for that case.

[deleted]

Re: New Features in Ruby 2.4

#27
Ruby is the first language I really like. The core concept of the language is small, just not easy to get, but the change on how to programming is significant. Sadly, Ruby is not the language for the multi-core world, and many advantages of using it is disappearing. Although Ruby is changing, 2.3, 2.4, maybe 3.0, but what's the difference?

Re: New Features in Ruby 2.4

#29
post #27

Ruby is the first language I really like. The core concept of the language is small, just not easy to get, but the change on how to programming is significant. Sadly, Ruby is not the language for the multi-core world, and many advantages of using it is disappearing. Although Ruby is changing, 2.3, 2.4, maybe 3.0, but what's the difference?

> Ruby is not the language for the multi-core world, and many advantages of using it is disappearing

Not really; it depends on the audience. The Ruby audience is still mainly Rails development, whose paradigm is multi-process.

Re: New Features in Ruby 2.4

#30

These are all great but when are we getting optional typing? If the js ecosystem wasn't a clown operation my language of choice would be typescript instead of ruby.

It's not on agenda and it will never happen. There are so many languages with fine typing, why break a dynamic one by adding stuff to it?
Post reply on HN