Friday, 13 March 2026

Named Versus Positional Notation in Functions and Methods

For as long as I have used functions and methods in programming, the default mode for me has been Positional Notation. Now, one may ask, what's Positional Notation?

Positional Notation is the method in which a function in a programming language identifies its parameters - by the positional order in which they are introduced. This example is in PHP.
function x($a, $b)
{
    //code here
}


In this call to the function x(), the value of a is 100 and the value of b is "abc". This is because the value 100 appears first, as does the parameter a in the function specification for x(). And the value "abc" appears second, as does the parameter of b.
$y = x(100, "abc");


Years back, I picked up Python and found out about Named Notation. This is a function declaration in Python.
def x (a, b):
    //code here


This is the way it's called in Positional Notation. No surprises there.
y = x (100, "abc")


And this is the way it's called in Named Notation! Note that in Named Notation, the argument values are directly assigned to the parameter names.
y = x (a = 100, b = "abc")


Or this. Because in Named Notation, the positional order no longer matters!
y = x (b = "abc", a = 100)


Why I love this...

Named Notation trumps Positional Notation. I'm sorry for fans of the latter; it's not even close.

Getting the order of arguments wrong has introduced many a bug in the code. In the case of a language like PHP, this is made even easier because PHP's parameter positions are notoriously (and annoyingly) inconsistent. Check out the definitions for strstr(), str_replace() and in_array(). The absence of Named Notation, thankfully, appears to have been fixed in PHP 8.0.

Position no longer matters.

Another thing about not needing to adhere to Positional Notation, is that if the programmer decides to add parameters to the function definition later, this makes it easier to do without breaking any existing implementations. In other words, this is great for extensibility.

...and why I don't

For Named Notation to work, a programmer needs to know the names of the parameters of the function or method they're attempting to call. This is often found in the documentation. A badly spelled parameter name could ruin your day.

And in the case of functions with many parameters, this could get cumbersome. On the other hand, Positional Notation is worse if there are many parameters. Far, far worse.

The only, solitary one!

Specifying the name of a parameter could be superfluous if there is only one parameter. After all, if there is only one parameter and only one argument is passed in, it makes sense that the argument is meant for that parameter.

Conclusion

Named Notation is not new, but for some reason or other, it just has not been the default in passing arguments into functions the same way Positional Notation has. It's starting to change, with support for Named Notation taking hold in recent times. This can only be a good thing. I'm digging it.

And that's my position!
T___T

No comments:

Post a Comment