The syntax function_name(arg1, arg2, ...)
is used widely across various programming languages to invoke a function. Why is it necessary for the compiler or interpreter to require ()
to recognize it as a function call? If something is inherently callable, wouldn't function_name;
suffice to execute it?
In certain languages, you can execute a function or command using syntax such as function_name 'test';
or even function_name 'first' 'second';
. Bash is one example. Some constructs (e.g., 'echo' or 'include') operate this way as well, like in PHP.
Could parentheses have been reserved solely for establishing the order of precedence, making them optional elsewhere? For instance, if expression == true function_name;
would've been as valid as if (expression == true) function_name();
.
A particularly interesting case is the use of 'SOME_STRING'.toLowerCase()
in JavaScript, where no arguments are required by the prototype method. Why did language designers opt against the simpler 'SOME_STRING'.lower
design in this case?
Disclaimer: I genuinely appreciate the syntax design of the C-inspired languages! I'm merely curious about the rationale behind this design choice. Does requiring ()
provide any genuine benefits, or does it simply enhance code readability for humans?
()
, 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
:)