
Ruby 2.6 - merk_
https://anamaria.martinezgomez.name/2018/12/21/ruby2_6.html
======
maxfurman
I am always happy to unwrap my Christmas present from the Ruby team! Some
questions about this release:

\- Are there any benchmarks for the new JIT?

\- Why was `(Date.today..(Date.today + 1)) === DateTime.now #=> true` false in
Ruby 2.5? It seems correct that right now is between today and tomorrow. Is it
because one is a Date and the other a DateTime?

~~~
koolba
Been a while since I’ve used any Ruby but isn’t the first expression a range
where’s the second a single value?

It’d be like [0,1] === 0

~~~
chrisseaton
> isn’t the first expression a range where’s the second a single value?

`===` conventionally means 'matches', or 'includes', so an aggregate on the
LHS and a scalar on the RHS is typical.

It isn't defined for `Array` beyond being the default of equality - I don't
know why - but it is defined for `Range`.

------
Lordarminius
Fantastic Christmas present from the Ruby team.

Ruby is alive and well despite all the rumors of it's demise. I predict a
resurgence in its use over the next few years.

Can't wait to examine and try out the new features.

~~~
JamesAdir
What makes you think there'll be a resurgence in its use in the next few
years?

------
ajmurmann
Ruby used to be my most beloved language. I've since developed a strong
appreciation for good type system. However, working with collections of any
kind in Ruby is just such a joy. The methods around it are so well thought
throug and make writing code a joy that in most other languages just would be
tedious. On top of that the Ruby team is constantly working on making that
aspect even better. I truly don't understand why it seems to me that no other
language I use makes even an effort to provide something similar. Getting a
map, a reduce and a filter function seems to be as far as most standard
libraries are willing to go.

~~~
astazangasta
Can you comment on why a good type system became so important to you? I can
understand the value in interfaces but not really in any other context.

~~~
Redoubts
Languages without ADTs and Optionals just feel impoverished.

~~~
yxhuvud
Languages without full blown union types feel so impoverished. With good
language typing support (including flow typing), optionals feel quite
redundant.

~~~
int_19h
But optionals are just a union type (T | None).

------
stevev
This will be fun. I’m glad we now have some performance improvements to some
common methods. For those considering playing with Ruby, you should! One thing
I’m surprised not many has mentioned what makes ruby unique and awesome,
BLOCKS!

~~~
dreix
Aren't they like arrow functions in JavaScript?

~~~
avandecreme
Just parameters that are functions, except that you can only have one per
function. I still fail to see the advantage of blocks over being able to pass
functions as arguments like in other languages.

~~~
kbp
One nice feature of blocks is that `return` will return from the enclosing
function, rather than the block, so you can write:

    
    
        def find(x, l)
          l.each do |y|
            return y if y == x
          end
        end
    

Where in Lisp you'd use (return-from find x) and in other languages you might
pass in a continuation or use a special return value protocol. It's a nice
solution for higher order functions that are supposed to feel more language-
level.

Also, you can pass functions as arguments like in other languages; lambdas
behave like you would expect them to.

------
augustl
Really like the idea of using lazy ranges instead of magic negative indices!
I.e `xs[6..]` instead of `xs[6..-1]`.

~~~
pulisse
Negative indices aren't magic. They follow the obvious wraparound (modular)
pattern: Negative `i` indexes the element in array `a` located at `i %
len(a)`. If they worked any other way it'd be madness.

~~~
viraptor
I don't think you got that index calculation right. -1 in array of 5 elements
is located at 5-1 == 4, not at 1%5 == 1.

~~~
pulisse
I don't follow your point. We're concerned with the value of -1 % 5, not 1 %
5. There's no definition of the modulus operator on which -1 % 5 = 1.

~~~
viraptor
Phrasing issue, I think. I understood "Negative `i` indexes the element" as
`i` itself being positive. Like you'd say "negative 1 indexes" (i is 1), not
"negative -1 indexes" (i is -1)

------
mmahemoff
> Constant names can now start with non-ASCII capital letters. I am not sure
> how useful this is

Very? If you want to code in non-Latin languages.

Also, π = 3.14159

~~~
ascar
I'm not sure about this being good for coding in non-latin. It might actually
encourage behavior to mistreat ruby constants as regular variables. IIRC
constants are not really constant, but only visual help for reading code and
ruby just issues a warning on reassignment and these warnings are not shown by
default.

I can totally imagine new devs just trying out non-ascii variables, see it not
crashing and then actually writing all their code using constants.

~~~
dragonwriter
> I can totally imagine new devs just trying out non-ascii variables, see it
> not crashing and then actually writing all their code using constants.

Ruby _already_ supported non-ascii identifiers for variables; 2.6 added
support for non-ascii first characters of constants, which must still be
capital letters, as had always distinguished constants from variables. It
doesn't make anything non-ascii a constant, it just makes constants consistent
with other identifiers in terms of non-ascii support, while preserving the
“initial capital means constant" rule.

And, as sibling comments note, reassigning a constant produces a warning, so
devs making a mistake and using constants for variables (regardless of ascii-
ness) will quickly be informed of their error.

~~~
ascar
I wasn't aware of non-ascii variables. I was thinking about UTF support for
Japanese characters, when I read the change. There is no concept of
lowercase/uppercase. 日本語 is this a constant or variable?

~~~
dragonwriter
Since constants are the exception, and used to require an ASCII capital but
now can start with ant capital, an identifiers starting with a Unicode
character in a script that doesn't have upper/lower case distinction is a
variable, not a constant.

------
alfredmuffin
Is it a good time to learn Ruby? I mostly do React and Node + Java work
professionally, but I've been looking into Ruby as a fun side project
language. I would appreciate any anecdotes!

~~~
jb3689
Ruby isn't perfect but it's a great utility language and can do a lot of
powerful things with very little effort. Read through Eloquent Ruby

The only problems I wouldn't go to Ruby for are CPU intensive ones or ones
where I need parallel threads (which you already have Java for)

~~~
Gravityloss
You can also use JRuby. Powerful and can be very easy to the user.

~~~
jwdunne
Had a problem that I'd typically use Ruby for but needed to shed the GIL.
JRuby worked beautifully. The only gotcha was I needed to use the JDBC driver
for Sequel instead of the usual drivers. Obvious in hindsight but not so much
with zero JVM development experience. I'd use it again.

------
lloeki
The access to AST will allow for neat hacks like PonyORM on Python, which
could be a way for me to improve Rebel::SQL. Tentative hacks by decompiling
bytecodes or using Parser, while fun, proved practically unsatisfactory.

[https://ponyorm.com](https://ponyorm.com)

[https://gitlab.com/lloeki/rebel](https://gitlab.com/lloeki/rebel)

------
saagarjha
What is the complexity of set operations on arrays? This seems a bit too much
sugar to me, to the point where people will end up writing inefficient code
because they will thing these methods are more performant than they really
are. Usually, I like to see explicit conversions to sets to make the
performance characteristics explicit.

~~~
mmahemoff
In most real world applications, the cost of doing an in-memory data
manipulation like this is negligible compared to I/O, waiting for the database
etc. It's already the wrong language for someone who wants to squeeze out
every CPU cycle, and imo it's a Good Thing for a language upgrade to embrace
its strengths ie syntax sugar in the case of Ruby, as long as the perf hit
isn't out of control.

I'd agree developers should pick the right data structure for the job and some
APIs can obscure the cost to the point of misleading developers into woefully
wrong decisions. I just don't think it's the case with array ops like union as
it's easy enough to handle them efficiently. I too would be interested to see
any benchmarks though.

~~~
saagarjha
I might be more receptive to this if this was added to all collections, then,
rather than just arrays. (Maybe it was? I don’t write Ruby, so I don’t know
for sure. Maybe Ruby doesn’t have a generic “collection” protocol?)

~~~
mmahemoff
Interesting point. Ruby has an Enumerable module, but these methods were added
only to Array. Since the main native collections (Set/Hash/Array) all support
them now, they could probably be added to Enumerable in the future, with
class-specific optimizations if necessary.

------
maximegarcia
one shot mode [1] for coverage will be handy in production as it has quite no
overhead. Happy xmas Ruby devs!

[1] [https://bugs.ruby-lang.org/issues/15022](https://bugs.ruby-
lang.org/issues/15022)

------
akulbe
I was trying to go download the latest Ruby or even read the latest release
notes, but the site seems to be down. It's still ruby-lang.org, right?

~~~
akulbe
Weird. I googled "ruby 2.6 download" and links from the results worked, but
simply trying to browse to "ruby-lang.org" times out.

~~~
steveklabnik
It just resolved for me. Maybe it'll clear up for you soon!

------
diminish
Am I the only one to find -rcX and -previewX type of versioning confusing.
like how much time is remaining etc.

------
j1elo
For when Ruby 3.x?

They should release soon, if we are to start seeing some decent adoption by
2028.

/pythonicsarcasm

------
rurban
> non-ASCII constant names

This is actually a security risk, avoiding all Unicode security
recommendations. See e.g. [http://websec.github.io/unicode-security-
guide/visual-spoofi...](http://websec.github.io/unicode-security-guide/visual-
spoofing/)

All they did was open the floodgates:
[https://github.com/ruby/ruby/commit/f852af0e59899157ef695edc...](https://github.com/ruby/ruby/commit/f852af0e59899157ef695edccbe86d51fc04d23b)

no rtl checks, no spoofing, no mixed script checks, no normalization.

~~~
tedunangst
How is it it a security risk to name a constant in source code?

~~~
pawelmurias
it can be used to create malicious pull requests that are visually
indistinguishable from correct ones

~~~
dragonwriter
> it can be used to create malicious pull requests that are visually
> indistinguishable from correct ones

If your only check on the correctness of submitted code is visual inspection,
you've got a much bigger problem than Unicode confusability.

~~~
saagarjha
How do you check your code? Presumably, you’re not able to exercise the full
range of inputs, so at some point you will have to look at the code and figure
out what it is doing…

~~~
heartbreak
Which means you'd notice the value of a constant being exfiltrated, since a
maliciously named constant doesn't magically expose secrets outside of the
application.

~~~
majewsky
I suggest you take a look at some of the submissions in e.g. the Underhanded C
Contest. Where it can be excruciatingly hard to figure out where the backdoor
is even though you _know_ that the code has one.

