r/programming • • Dec 25 '16

Ruby 2.4.0 Released

https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/
56 Upvotes

9 comments sorted by

5

u/NeuroXc Dec 25 '16

Wait a second...

[x, y].max and [x, y].min are optimized to not create a temporary array under certain conditions.

Why would you need to ever create a temporary array to find the max or min in an array?

17

u/Hueho Dec 25 '16

The devil is in details. And also in unclear explanations!

Normal #min and #max methods don't allocate other arrays, the problem is that is idiomatic in Ruby to calculate the max/min of 2 variables by wrapping them in a array literal and calling the respective method, instead of doing a if or ternary. This of course has much bigger overhead, including an useless array allocation.

The change is essentially just rewriting these occurrences in the bytecode compiler to the simple version.

0

u/[deleted] Dec 25 '16

[deleted]

12

u/shevegen Dec 25 '16

Because the future is built on the past 10 years - or something?

The hilarious part is that the other side of the argument would be "why are there two different things for integers - isn't that making ruby more complex".

Don't slow down those who can move fast.

0

u/[deleted] Dec 25 '16

[deleted]

4

u/bluejimmy168 Dec 25 '16

I only use Ruby for Rails. It seems like you use ruby for other stuff. If you dont mind, can i ask you what you use ruby for?

2

u/doublehyphen Dec 26 '16

I use Ruby for most of my stuff where performance or concurrency is not requirements. Web (using Sinatra rather than rails), automation, simple crawlers, etc.

3

u/601error Dec 25 '16

I only use Ruby for system admin, text processing, and macOS package management.

4

u/shingtaklam1324 Dec 25 '16

Not previous poster, but building small games with Gosu is lots of fun, small scripts for parsing text documents and scripts for larger games.

2

u/bluejimmy168 Dec 25 '16

cool, I love ruby but can not find a reason to use it more often.

2

u/Solon1 Dec 25 '16

Except that every C extension you actually need and didn't suck, has already been ported to 2.4.0