News for hackers. Stuff that matters.
Re:A Javascript journey with only six characters by catscratch on Saturday October 08, 2016 @10:39AM (#12667075)
This doesn't make me want to use JS. The power of JS is in two things, it's in every major browser and it doesn't completely suck. JS syntax kind of sucks. The power in JS is that it's dynamic and lets you send functions around, but defining functions is much uglier than defining a lambda in Ruby:

-> {anything goes here}

or

->(a,b,c) {anything goes here}

The problem with Ruby is that you then have to .() the lambda vs. (), so that is more verbose than just calling the function.

If browsers were to embrace a language that was more Ruby-like and less clunky than JS, I'm sure I'd use it more.

Re:A Javascript journey with only six characters by dcwca on Saturday October 08, 2016 @12:30PM (#12667507)
Ruby suffers from a confusing set of overlapping features in Procs, Blocks and Lambdas. JavaScript's function passing is a lot less opaque.
Re:A Javascript journey with only six characters by zuck9 on Saturday October 08, 2016 @10:45AM (#12667097)
ES6 lets you define functions like a => a * 2

Or (a, b, c) => a * b ^ c

Re:A Javascript journey with only six characters by catscratch on Saturday October 08, 2016 @11:02AM (#12667150)
That's succinct, but less clear than the Ruby version, imo, as you don't have any scope indicators required for the function body.

JS:

  let f = (a,b,c) => a * b ^ c;
  f(2,3,4);
vs. Ruby:

  f = ->(a,b,c) { a * b ^ c }
  f.(2,3,4)
Ruby's shorter and clearer. But, when you use the Ruby lambda more than once in the code, you lose the brevity advantage, because of the "extra" dot. But, in Ruby I use methods more than lambdas, which would be:

  def f(a,b,c) { a * b ^ c }
  f(2,3,4)
Re:A Javascript journey with only six characters by notyourwork on Saturday October 08, 2016 @02:45PM (#12668062)
> Ruby's shorter and clearer.

I would say the different is negligible here and claiming one is more clear than the other is purely preferential. Coming from a JS background the JS is more clear but not substantially enough for me to claim it is outright more clear a language syntax. Someone coming from a ruby background may argue the other direction.

Some languages are quite different but you are splitting hairs here and trying to be conclusive about it.

Re:A Javascript journey with only six characters by qaq on Saturday October 08, 2016 @11:27AM (#12667245)
None is preventing you from writing let f = (a,b,c) => {a * b ^ c}; in JS
Re:A Javascript journey with only six characters by 1000hz on Saturday October 08, 2016 @12:33PM (#12667517)
when you include curly braces in arrow functions you lose the implicit return, so this function would return undefined
Re:A Javascript journey with only six characters by johnhenry on Saturday October 08, 2016 @01:20PM (#12667730)
You can get the implicit return if you use parentheses instead:

f = (a,b,c) => (a * b ^ c)

Re:A Javascript journey with only six characters by qaq on Saturday October 08, 2016 @12:35PM (#12667522)
very true :)
Re:A Javascript journey with only six characters by 8note on Saturday October 08, 2016 @01:42PM (#12667816)
the ruby versions isnt shorter though; you just included things you dont need: semi colons and 'let'