Skip to main content
improve title and tags
Source Link
David Refoua
  • 1.2k
  • 1
  • 12
  • 17

Syntax Design - Why use parentheses for function call when no arguments are passed?

In many languages, theThe syntax function_name(arg1, arg2, ...) is used widely across various programming languages to callinvoke 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.Why is it necessary for the compiler or interpreter to require () to recognize it as a function call? If something is known to beinherently callable, why wouldn't function_name; be enoughsuffice to execute it?  

On the other hand, in someIn certain languages we, you can do:execute a function or command using syntax such as function_name 'test'; or even function_name 'first' 'second'; to call a function or a command. Bash is one example. Some constructs (e.g., 'echo' or 'include') operate this way as well, like in PHP.

I thinkCould parentheses would have been better if they were only needed to declarereserved solely for establishing the order of priorityprecedence, and in other places weremaking them optional. For example elsewhere? For instance, doing if expression == true function_name; should bewould've been as valid as if (expression == true) function_name();.

An especiallyA particularly interesting case is writingthe use of 'SOME_STRING'.toLowerCase() when clearlyin JavaScript, where no arguments are neededrequired by the prototype functionmethod. Why did thelanguage designers decideopt against the simpler 'SOME_STRING'.lower design in this case?

Disclaimer: Don't get me wrong, I quite lovegenuinely appreciate the syntax design of the C-like syntaxesinspired languages! I'm just asking formerely curious about the reasoningrationale behind itthis design choice. Does requiring () haveprovide any actual advantagesgenuine benefits, or does it simply make theenhance code more human readablereadability for humans?

Syntax Design - Why use parentheses when no arguments are passed?

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?

Why use parentheses for function call when no arguments are passed?

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?

deleted 39 characters in body
Source Link
David Refoua
  • 1.2k
  • 1
  • 12
  • 17

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 oddstrange that a compiler or script interpreter would require () in order to successfullyactually detect it as a function call. If a variablesomething 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 opinionAn especially interesting case is to dowriting '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 syntaxsyntaxes! ;) I'm just asking iffor the reasoning behind it could be better. Does requiring () have any performanceactual advantages, or does it simply make understanding the code easiermore human readable? I'm really curious as to what exactly the reason is.

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.

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?

Tweeted twitter.com/StackProgrammer/status/785326881067376641

Syntax Design - Why use parentheses when no argument isarguments are passed?

In most language syntax designmany languages, the syntax function_name (arg1, arg2, ...) is used to call a function.

This is fine, but in some cases When we just want to call the function without any arguments, so we must do funtion_name function_name().

I find it outodd that a compiler, or a script interpreter, would always require () at the end of a function to successfully detect it as a function call. If a variable is known to be callable, why wouldn't doing 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.

The most annoying thing in my opinion is to do 'SOME_STRING'.toLowerCase() when clearly no arguments is passed, or even should be passed to the prototype function. Why the designers decided against 'SOME_STRING'.lower when it can be easily done and implanted?

Are there any advantages performance-wise, or does this makes understanding the code more easy? I am really curious as to what exactly the reason is.

I think parentheses would have been better if they only were only needed to declare the order of priority, and in other places using parentheses would have beenwere 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 syntaxessyntax! ;) I'm just asking if it could be better. I found the unnecessary usage of Does requiring () oddhave any performance advantages, which you actually gave some exampleor does it make understanding the code easier? I'm really curious as to whywhat exactly the reason is it important.

Syntax Design - Why use parentheses when no argument is passed?

In most language syntax design, the syntax function_name (arg1, arg2, ...) is used to call a function.

This is fine, but in some cases we just want to call the function without any arguments, so we do funtion_name ().

I find it out that a compiler, or a script interpreter, would always require () at the end of a function to successfully detect it as a function. If a variable is known to be callable, why wouldn't doing 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.

The most annoying thing in my opinion is to do 'SOME_STRING'.toLowerCase() when clearly no arguments is passed, or even should be passed to the prototype function. Why the designers decided against 'SOME_STRING'.lower when it can be easily done and implanted?

Are there any advantages performance-wise, or does this makes understanding the code more easy? I am really curious as to what exactly the reason is.

I think parentheses would have been better if they only were needed to declare the order of priority, and in other places using parentheses would have been optional. For example, doing if expression == true function_name; should be as valid as if (expression == true) function_name();.

Disclaimer: Don't get me wrong, I love the C-like syntaxes! ;) I'm just asking if it could be better. I found the unnecessary usage of () odd, which you actually gave some example as to why is it important.

Syntax Design - Why use parentheses when no arguments are passed?

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.

Question Protected by gnat
edited title
Link
Tulains Córdova
  • 39.6k
  • 13
  • 102
  • 157
Loading
added 217 characters in body
Source Link
David Refoua
  • 1.2k
  • 1
  • 12
  • 17
Loading
added 293 characters in body
Source Link
David Refoua
  • 1.2k
  • 1
  • 12
  • 17
Loading
Source Link
David Refoua
  • 1.2k
  • 1
  • 12
  • 17
Loading