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 odd that a compiler or script interpreter would require ()
to successfully detect it as a function call. If a variable 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();
.
The most annoying thing in my opinion is to do 'SOME_STRING'.toLowerCase()
when clearly no arguments are needed by the prototype function. Why did the designers decide against the simpler 'SOME_STRING'.lower
?
Disclaimer: Don't get me wrong, I love the C-like syntax! ;) I'm just asking if it could be better. Does requiring ()
have any performance advantages, or does it make understanding the code easier? I'm really curious as to what exactly the reason is.
()
, 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 5 '16 at 14:41