In many languages, the syntax function_name(arg1, arg2, ...) is used to call a function. When we want to call the function without any arguments, we must do function_name().
I find it strange that a compiler or interpreter would require () in order to actually detect it as a function call. If something is known to be callable, why wouldn't function_name; be enough?
On the other hand, in some languages we can do: function_name 'test'; or even function_name 'first' 'second'; to call a function or a command.
I think parentheses would have been better if they were only needed to declare the order of priority, and in other places were optional. For example, doing if expression == true function_name; should be as valid as if (expression == true) function_name();.
An especially interesting case is writing 'SOME_STRING'.toLowerCase() when clearly no arguments are needed by the prototype function. Why did the designers decide against the simpler 'SOME_STRING'.lower design?
Disclaimer: Don't get me wrong, I quite love the C-like syntaxes! I'm just asking for the reasoning behind it. Does requiring () have any actual advantages, or does it simply make the code more human readable?
var myFunc = function;– Matthew Oct 05 '16 at 13:53fun1( func2, 'test' ), but if we were to remove parentheses at all, I thinkfunc1 func2 'test'would be confusing as to which priority order should have been used. – David Refoua Oct 05 '16 at 13:54(), yet the thing that stands out in your post is theif (expression == true)statement. You worry about superfluous()'s, yet then use a superfluous== true:) – David Arno Oct 05 '16 at 14:41f a bis the equivalent off(a)(b)and not off (a(b)). In that case this syntax is very useful because it can be used for partial application:plus x y = x+y; add_three = plus 3; add_three 5 -> 8. – Bakuriu Oct 05 '16 at 15:03if (expr.something().length > 127)make you happy? :D jk man – David Refoua Oct 05 '16 at 16:50()withCALLdoesn't strike me as a particularly efficient replacement. In the end having functions as first class objects is incredibly useful and if you do that you need some way to distinguish between calling and referencing a function (you might just make it depend on the context of the expression - which can get confusing quickly -, but still there is something). There are different ways to do that, but there's little reason to introduce a weird distinction between function calls with parameters and without, particularly since you'll need something else instead. – Voo Oct 05 '16 at 23:06f(a function with no arguments) andf()(a function that is passed the unit argument), despite using e.g.f a bto pass two arguments to a function. – Luaan Oct 06 '16 at 13:10funcname, and use@funcnamewhen you want to pass it as an argument. I'm not saying that it's the best design choice in the world, but it works. One could even argue that the most common use should be the one that requires characters to type. – Federico Poloni Oct 06 '16 at 13:52@as an argument. – Matt Oct 07 '16 at 01:13IO somethingis a zero argument function in some way, but then passing it around doesn't call it, you have to extract the value inside theIOmonad... in the end in imperative languages all the results are of that kind. – Bakuriu Oct 07 '16 at 06:39IO something". You should stop thinking of every language in Haskell terms - saying that a zero-argument void-returning function in Java is a "value of typeIO ()" is as silly as saying a named value in Haskell is a "memoized function call". – user253751 Oct 07 '16 at 09:02func1 \&func2in Perl. Are you one of those silly Python users? – oals Oct 07 '16 at 13:22