7 ms·
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
by anomaloustho 6y ago
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.
- whichdan 6y agofwiw, most folks would just use Lodash[0]: import times from 'lodash.times' [0] https://lodash.com/docs/4.17.15#times https://lodash.com/docs/4.17.15#times
- xtracto 6y agoAnd that shows one of the main problems with JavaScript. People in my team have spent countless hours removing lodash dependencies from the codebase.
- still_grokking 6y agoWhy? It's imho a must have lib. JS feels incomplete without it.
- antihero 6y agoYou can get a bit nicer with something like [...new Array(1000)].foreach(() => console.log('Hello')) But yes, ruby is much nicer.
- edflsafoiewq 6y agoDon't allocate an array when you just need a for loop.
- suby 6y agoRight, what's wrong with just for (var i = 0; i < 1000; i++) { console.log("Hello world"); }
- cygx 6y agoNothing 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.
- antihero 5y agoThe console.log was just an example. This is just getting a range of numbers.