However trivial this may seem, I can’t help my curiosity. In your experience, what are some readability considerations when it comes to naming arguments and parameters? Arguments are in function calls and thus may serve a different human-readable purpose than parameters in function definitions. When should an argument name be more specific than its corresponding parameter name and vice versa, or should they carry the same name when possible?
Do you know of any conventions or criteria that would help decide one way or the other? Or would you say this is left to the realm of preference?
Thanks in advance.
Parameter and argument as terms are usually used interchangeably, but if we want to get more specific, then it usually boils down to this:
A parameter is just a name in function’s definition.
An argument is an object that will be passed to that function.
So, let’s say you’ve got a function that accepts a database connection:
Here,
dbConnectionis a parameter.When you actually use this function, if you’re using an Oracle database, you can name that
DatabaseConnectionasoracleDbConnectionand use it like this:Here, we have two things:
dbConnectionis the parameter nameoracleDbConnectionis the argument nameFrom this, we can see that the parameter name is usually more “generic” than the argument name, but it doesn’t have to be so. You can also just use
dbConnectionas the argument name, butoracleDbConnectionis more meaningful.