News for hackers. Stuff that matters.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by anomaloustho on Friday April 02, 2021 @03:26PM (#26675037)
I think Ruby can have some nice parts to reading it. e.g.

    10.times do
      puts “Hello”
    end
or

    send_email if user.unconfirmed?
Compared to ES6 as an example:

    Array.from(Array(10)).forEach((_, _i) => {
      console.log(“Hello”);
    });

Ooph, not the strongest showing by comparison. There isn’t a huge issue with it, but it is having to use a lot more indirection to express the main idea. Languages like Python get closer to that expressiveness as well, but I think Ruby goes even farther in the direction of expressive choice.

I don’t write Ruby anymore. But there were some nice things that I miss sometimes when using other languages. Sometimes I want to express a very simple idea that, while still readable, gets wrapped in brackets, parens, variable declarations, and type declarations to a point where it looks more intimidating and unapproachable than it actually is.

Re:Crystal Language That Aims at C Performance with Ruby Syn... by antihero on Friday April 02, 2021 @03:59PM (#26675316)
You can get a bit nicer with something like

    [...new Array(1000)].foreach(() => console.log('Hello'))
But yes, ruby is much nicer.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by edflsafoiewq on Friday April 02, 2021 @04:12PM (#26675439)
Don't allocate an array when you just need a for loop.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by antihero on Wednesday April 14, 2021 @10:40AM (#26807713)
The console.log was just an example. This is just getting a range of numbers.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by suby on Friday April 02, 2021 @04:34PM (#26675683)
Right, what's wrong with just

for (var i = 0; i < 1000; i++) {

    console.log("Hello world");

}
Re:Crystal Language That Aims at C Performance with Ruby Syn... by cygx on Friday April 02, 2021 @05:00PM (#26675945)
Nothing per se, but more declarative code is often nicer to look at than imperative code.

In the for loop example, you need to name and explicitly initialize a variable, you need to explicitly write down the comparison, and you need to explicitly increment the variable.

In the Ruby example, the plumbing is hidden from view, and you can just tell the runtime how often you'd like the thing to happen.

On a tangential note, in Raku (the language formerly known as Perl6), you could have written that as

    say("Hello world") xx 10;
That's pretty hard to beat, imo.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by whichdan on Friday April 02, 2021 @03:58PM (#26675310)
fwiw, most folks would just use Lodash[0]:

  import times from 'lodash.times'
[0] https://lodash.com/docs/4.17.15#times
Re:Crystal Language That Aims at C Performance with Ruby Syn... by xtracto on Friday April 02, 2021 @06:08PM (#26676480)
And that shows one of the main problems with JavaScript. People in my team have spent countless hours removing lodash dependencies from the codebase.
Re:Crystal Language That Aims at C Performance with Ruby Syn... by still_grokking on Friday April 02, 2021 @11:13PM (#26678160)
Why? It's imho a must have lib. JS feels incomplete without it.