News for hackers. Stuff that matters.
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.