News for hackers. Stuff that matters.
Re:Javascript: call functions without using parentheses by iamrohitbanga on Wednesday September 19, 2018 @02:38PM (#18026579)
I feel where Ruby's optional parenthesis syntax really shines is in method call chaining.

e.g.

    employees.flat_map(&:addresses).map(&:city).uniq.sort
    # in place of
    employees().flat_map(&:addresses).map(&:city).uniq().sort()
Re:Javascript: call functions without using parentheses by pavel_lishin on Wednesday September 19, 2018 @04:04PM (#18027263)
Oh thank god, we saved ourselves six characters! And the only thing we sacrificed is knowing for sure whether we're accessing an object's property, or calling a method!
Re:Javascript: call functions without using parentheses by goatlover on Wednesday September 19, 2018 @04:46PM (#18027553)
It's all methods in Ruby. Properties are private. You access them via methods.
Re:Javascript: call functions without using parentheses by globuous on Wednesday September 19, 2018 @03:27PM (#18026998)
As a non-Ruby programmer, this sounds like it makes it non-obvious whether you're calling a class' method or attribute. Do you end up relying on your editor to help you out ?
Re:Javascript: call functions without using parentheses by dragonwriter on Wednesday September 19, 2018 @04:08PM (#18027295)
> As a non-Ruby programmer, this sounds like it makes it non-obvious whether you're calling a class' method or attribute.

“Attributes” in Ruby are just methods that do attribute-like things, so there is no ambiguity: it is always a method.

Re:Javascript: call functions without using parentheses by wongarsu on Wednesday September 19, 2018 @05:06PM (#18027711)
Every langauge with native support for property setters and getters has the same problem. C# has decent IDE support, in JS we pretend it never happens, Ruby is at least upfront
Re:Javascript: call functions without using parentheses by techazard on Wednesday September 19, 2018 @03:44PM (#18027135)
It's actually nice that it does not matter if it's a function or attribute that your calling in ruby. Check out the Uniform access principle (https://en.wikipedia.org/wiki/Uniform_access_principle).

When used correctly you can write IMHO really clean and concise OOP code where (cascading) changes are easily made.

Re:Javascript: call functions without using parentheses by pavel_lishin on Wednesday September 19, 2018 @04:05PM (#18027270)
Where this kills me is ambiguous commas.

    something = [ alpha beta, gamma ]
I have no idea if I just invoked alpha(beta, gamma) and put the result into a single-member array, or if I've got an array with two elements - alpha(beta) and gamma.
Re:Javascript: call functions without using parentheses by techazard on Wednesday September 19, 2018 @05:15PM (#18027782)
Yep you can create ambiguous nasty code like this. It's is clearly not expressing intent, so you would add parentheses.
Re:Javascript: call functions without using parentheses by dragonwriter on Wednesday September 19, 2018 @05:09PM (#18027735)
It's not actually ambiguous; though it is a bit of language-specific syntax to learn.
Re:Javascript: call functions without using parentheses by iamrohitbanga on Wednesday September 19, 2018 @05:17PM (#18027799)
Agreed. It is the "idiomatic" way of writing code in Ruby. I love Java but writing lambda expressions in Java with deeply nested parenthesis makes the code really ugly and less readable esp with chaining.

As far as I understand, Ruby style is writing the code in the most elegant way to increase readability and (hopefully) reduce chances of bugs.

Re:Javascript: call functions without using parentheses by pavel_lishin on Thursday September 20, 2018 @12:15PM (#18033550)
So what would you expect my example above do, at a glance?

Or is my example something that a good Ruby developer never write at all?

Re:Javascript: call functions without using parentheses by pavel_lishin on Thursday September 20, 2018 @11:11AM (#18033007)
It's not ambiguous to the computer, but it is ambiguous to a human at a glance.
Re:Javascript: call functions without using parentheses by fake-name on Wednesday September 19, 2018 @03:56PM (#18027210)
As someone who writes basically only C++ and Python, that code looks like a nightmare.
Re:Javascript: call functions without using parentheses by yen223 on Wednesday September 19, 2018 @08:51PM (#18028876)
Python has the `@property` decorator, which effectively disguises method calls as attribute access. To me, that's as bad, if not worse, than the ruby code posted above.