Hacker News new | past | comments | ask | show | jobs | submit login

Interesting! I’m surprised you didn’t move to Elixir given the syntax similarities to Ruby



While elixir's syntax is inspired by ruby, the semantics are vastly different. That change in semantics is really good for elixir, because it means it can take advantage of the unique properties of the erlang vm, but it's worth noting that crystal is far far closer to ruby than elixir. For better and for worse.


The syntax similarities between Elixir and Ruby stop as soon as one moves on from reading short blog post to writing real code. They are extremely different languages. Knowing Ruby helps only to remember the names of some standard library modules and functions, which were designed on purpose to match the name of the corresponding Ruby modules and methods, but not all of them. A vanilla example:

    $ iex
    > "1 2 3" |> String.split |> Enum.map(fn x -> String.to_integer(x) * 2 end)
    [2, 4, 6]

    $ irb
    > "1 2 3".split.map {|x| x.to_i * 2}
    [2, 4, 6] 
which by the way highlights the extra verbosity of Elixir compared to Ruby. It's less verbose on more complex examples, mainly because of pattern matching, but the proof would be too long for this reply.


Kotlin syntax:

"1 2 3".split(' ').map { it.toInt() }


Your example doesn't do the same thing.

The same as grandparent, in crystal:

  "1 2 3".split.map &.to_i.*(2)


I believe that Ruby also has that & shortcut (or similar) but it's totally unreadable. I never used it and I don't even want to check the exact syntax. Is it the only way it works in Crystal?


It being readable is a matter of getting used to it. I find it more readable than the block version as there is less syntactic boilerplate. YMMV.

Ruby has a similar version using colon instead of dot but that version isn't chainable and doesn't take arguments so it can't do the *2.

And no, you can write out the full block just as you did in the Ruby version.


Whoops, you're right.

    "1 2 3".split(' ').map { it.toInt() * 2 }


I hear this a lot but I keep seeing more and more Ruby devs moving to it trivially and as someone who reads-not-writes Ruby code I find it just as trivial to grok it.

So I think the differences are there but they’re being overstated from a transfer of skills standpoint.


Differences don't necessarily make it hard to move to another language. Many developers moved from Java to Ruby between 2006 and 2010, including me, and Ruby is pretty different.


Elixir would probably not have been a huge improvement over Ruby if they switched languages for performance reasons. Elixir is great for many things, but raw number-crunching performance is not one of them.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: