I read the first chapters of Clean Code by Robert C. Martin, and it seems to me it's pretty good, but I have a doubt, in one part it is mentioned that it is good (cognitively) that the functions should have as few parameters as possible, it even suggests that 3 or more parameters is too much for a function (which I find very exaggerated and idealistic), so I started to wonder...
Both the practices of using global variables and passing many arguments on the functions would be bad programming practices, but the use of global variables can greatly reduce the number of parameters in the functions...
So I wanted to hear what you think about it, is it worth using global variables to reduce the number of parameters of the functions or not? In what cases would it be?
What I think is that it depends on several factors:
- Source code size.
- Number of parameters in average of the functions.
- Number of functions.
- Frequency in which the same variables are used.
In my opinion if the source code size is relatively small (like less than 600 lines of code), there are many functions, the same variables are passed as parameters and the functions have many parameters, then using global variables would be worth, but I would like to know...
- Do you share my opinion?
- What do you think of other cases where the source code is bigger, etc.?
P.S. I saw this post, the titles are very similar, but he doesn't ask what I want to know.