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