Without taking into consideration a specific programming language, what would be the difference between parameters and arguments in terms of functions?
Also take into account that according to what I understood from the "clean code" book, it is recommended that the fewer arguments (if possible none) that are passed to the function, the more effective it becomes, why?
If you can add an example of both much better :)
A parameter is an intrinsic property of a procedure, since it is included in its definition. For example, a procedure that computes the sum of two integers will require two parameters, one for each number. In general, a procedure can be defined with any number of parameters (or none at all). If a procedure has parameters, the part of its definition that specifies them is called the parameter list.
Meanwhile, the arguments are rather the actual values assigned to the variable parameters when the function is called.
When a function call is made, the "values" passed in are called arguments.
In practice, there is usually no clear distinction between the two terms.
I leave you the official documentation of MSDN .
In addition to what our colleague sakulino says in his answer , I also want to contribute something, since the main difference between parameter and argument is the same as "identifier and value" in a nutshell.
But my addition goes to what you ask is the following:
Small edit: Well, the effectiveness of a function depends on how it was created and if it fulfills its purpose.
That is, because in most operating systems all compiled code performs an action, the code itself is not interpreted by the computer (otherwise they would be human!) , but the only thing the computer understands is a combination of
0
and1
throughout the program.It happens that when calling a function, at the bit level, no arguments are passed, but all those bytes are loaded into registers, imagine the following example:
The computer doesn't know what it's getting, so it just interprets the function arguments in reverse (On some systems) :
This is not real assembler
And in the body of the function, make the respective moves to avoid using memory addresses.
The reason why a function without parameters can be more efficient than one with parameters, is because the computer interprets only one call, that is, the greater number of parameters, the greater number of register assignments, therefore a little slower ( Or at least that's what I understand)
In a function with no arguments you just do:
And ready.
The idea of using few parameters seeks precisely that: clean, readable code, easy to understand, write, read and maintain. If you find a function with, for example, 16 parameters, it is not easy to read it.
For example, suppose you have a function to register a new customer, and you use it like this:
As you can see, it is a very long instruction, you have to go through it completely to observe the content, and when you write it, it is easy to lose the order of the parameters (it has happened to me personally) and make mistakes, and if they are of the same type it will not show no mistake (for example, that you change a last name to a first name) and it will be more difficult to detect the problem. If you are debugging it is also difficult to follow the order of the parameters. And that's not counting if, in turn, the function
IngresarNuevoCliente
belongs to the business logic and in turn calls another function to store this information, which will also have N number of parameters.It is very different, for example, to use a class
Cliente
, create an objectcliente
and assign values to it as you get the information:And then create the new client like so:
Its writing and reading is clearer, during a debugging you can analyze the object and there the information will be available in a more readable way.
What if you later need to capture more customer information? You simply modify the class and you can now capture this information without modifying your function, which would add more parameters to the function and make it more complicated and prone to errors, as well as all the functions that it calls.
The idea of completely avoiding parameters seems a bit far-fetched to me, in general these are good practices, not laws written in stone , and as you gain experience writing code, you will know which ones to take into account and why.