Please, somebody standadise the order of function variables
By Iain Cuthbertson
Finding a needle in a haystack is a wonderful bit of symbolism and I welcome its use in many situations.
It’s just the implementation of that symbolism that needs to be standardised. For forgetting the order in which a function expects variables to be passed in is tedious.
In PHP, for example, there are some very useful functions: in_array() and str_pos() to name but two.
Usage is in_array($needle, $haystack)
and makes sense as you want to check that the needle is in the haystack.
But, it’s strpos($haystack, $needle)
that messes things up. You can’t look for a haystack within a needle!
So, because of strpos()
confusing things, it’s quite often that I (and other’s I’m sure) mix the order, no matter which function is in use. Unless I’ve been using the function within the last few hours, I’ll most likely get it wrong.
These are long standing functions in a well established language, so there’s no hope of these ever being corrected.
For new functions, a possible answer would be to pass variables by associative array when the function has more than 1 variable input.
An example of calling such a function would be: myFunction(array('needle' => 'malteser', 'haystack' => 'bag_of_revels'));
This way, it wouldn’t matter which order you remembered to pass in the variables. As it happens, this is how I write my own functions.
Apparently, something similar is done in Python. Might get around to learning it sometime…