It doesn’t exist, and I’m going to say that anyone who says they do loses credibility with engineers "for real".
Book review
A book that I think people should read was quoted in the answers. But I’m afraid they will actually read it. If one is prepared to read, that is, to have a critical thinking, to understand scientific method, to already have the foundations of software engineering, which are pragmatic and neutral, not to mention to be able to interpret text properly and to understand the context of the book, that is not written in it, then reading it can give you ideas, provoke questions, suggest techniques, and can propose good things.
That goes for everything in life. I especially find the book disastrous in the hands of those who are unable to select what helps and what hinders them. And it’s a problem in what is not obvious. And obviousness depends on each one. Some consider that 17 lines of code is the maximum size a function should have. And don’t argue with the person. I can’t even imagine why it’s not 16, or 18, or 13, or 23.
Criticism of the state of society’s "thinking"
When someone says things that cannot be affirmed without saying that it is a joke, or that justifies deeply, what is almost always said to consider as a joke, distrust the author. Delivering something "concrete" works just as well as marketing. People like clear, straightforward answers, even if they’re fake. If that wasn’t the case fake news did not prosper (and people do not usually even know what it is fake news, most think it’s the literal translation). Validating what a person believes, and that’s easier when they have little basis on what they think, is very powerful. So much so that even those who have good philosophical basis fall into this.
Critique of the book idea
One of the mistakes you make is you don’t look at the context. The book does not have a clear context, but it has an implicit one, and the fact that you do not know easily is already an indication that you should distrust what is there. It depends on the type of code, the type of team, the type of technology used.
It has scenario that fits some criterion. But it does not fit in several others. What counts is the common sense. I think the book quote is interesting even in isolation. But only if you understand that this is a useful theory, not an always applicable practice. You have to look at the alternative. Is it a benefit or not?
Creating an object just to encapsulate parameters that are naturally parameters, and not parts of an object, is one of the stupidest ideas I’ve ever seen. Encapsulating data in a single object that makes sense to be together, and that this can be used in some places makes a lot of sense, in many cases.
Criticism of generic response
Nothing wrong with it, just think it was given an emphasis to the type of project and team without considering that even within a team or project has different needs at each time, at each point. The micro context should be considered more than anything else. To think that a team deciding how to do it is good, is interesting from a political point of view, but not from an engineering point of view (in some cases it does too), each shooting to one side is not good engineering. It just bothered me a little bit the last paragraph that treats the acceptable in a generic way. What is understandable that is done.
Criticism of the PHP response
The answer is not bad. I just don’t agree with her basic idea, far from being wrong. I’m not fascistic.
In general they do not do so in low ceremony languages, with naturally self-contained codes. Especially it makes no sense in PHP. And even if I did, I don’t see why I shouldn’t wear one array simple, even associative that only exists in that context. Creating a class just for that already tends to be bad in Java, in PHP even more.
Counterpoint
But Java has a justification. It is a language that values performance, and sending several parameters can be expensive. And the only way to create a heterogeneous structure to go through references is to create a class. Still, there will only be gains if you don’t create the object just for this, it will exist in a larger context within the application. It will never be a good idea to create the class just for this. Nor from an organizational point of view. This is complication and not simplification. People have lost sight of what’s simple.
In PHP without performance being a requirement and having another better mechanism makes even less sense.
It is a right of each author of what you want to transmit, but adapting Clean Code to PHP would be interesting if the adaptation had done almost everything backwards (I’m exaggerating a little here :) ).
Bringing software engineering from scratch
Curiously this done without criterion decreases cohesion and can increase coupling, and this is an old concept, much more than the book, this original idea that makes sense.
An interesting point to show that the citation in isolation is already flawed, is that this applies to functions or methods. Because with this whole accuracy of the ideal quantity, a difference parameter already changes a lot. Method has one more parameter that is not visible, it counts or not?
Continuing
I think the answer that was most voted on was rather sensitive in relation to this, it just lacked to justify a little more, so I decided to answer. If there are several authors saying different things is the show that has no ideal number.
My justification
Of course, a small number is interesting, no one can deny.
Some say that zero is not good, but this is fundamentalism, there are cases that communication requires it, it may be that it accesses external resources without needing any configuration, what would make a parameter be exaggerated because if it is only to configure the function, may be the case of separating the function into more than one, keeping as an abstraction for something larger within the DRY.
When there are too many parameters, it stinks. But what is bad depends on the context, even the smell of gas (which is artificially bad) is good because it does what it proposes. Smell is indicator, not proof.
Perhaps the cat’s answer shows something that deserves an object (not necessarily class), not because of the parameters, but because it is cohesive to be one thing, for every application. A well thought out would already have this object naturally, there is nothing to discuss. My criticism is to create abstraction without reason.
I know from experience that functions with more than 4 or 5 parameters usually have something wrong, but not all. I know that if you have many functions like this, with the same parameters it is usually something very wrong. But only usually.
One of the indications of many parameters is that the function has many responsibilities, so the solution is not to decrease the number of parameters is to separate the responsibilities. No use finding the problem, you have to find the right solution. Creating a class is not the only solution.
Answering the question more directly
Short form (1) and readable (2) is never write more code (1) and delegate to another location (2). We write more and in another place when needed, when it brings a greater advantage than the disadvantage it brings together.
Always someone will mess with your code, you for example. Few people have the ability to remember everything you’ve done after a while. I also criticize those who have this ability and use it as if everyone should have.
See? I have the same difficulty as the AP, the number is close to his, and little more than the book. But I’ve worked well with functions with 7 or more parameters. And where there were many the solution was not to create a class, because it did not solve any problem, it only remained a shorter stretch, anothers stayedm longests.
A much bigger problem with this function is that it uses little-readable names.
It has language that has named arguments to avoid the difficulty of understanding what is being passed. If the language doesn’t have is a shame, bad choice, but it still has comments, right? You can use /*argumentoX*/
. It’s funny that nobody thinks of these things to solve the problems. It must be because it’s not in any cake recipe that’s out there.
I don’t know the context to talk more about the example shown in the question. It may be worth having some form for the coordinates. But I have doubts.
I don’t know if PHP has any official recommendations. In general these recommendations are silly and being PHP twist a little more the nose since very important things to have something clear and objective, has not.
Having many parameters is clearly a antipattern. Just don’t think they should ever be used or that a number will establish when it’s normal or not.
I didn’t even mention the fact that parameter is not the same as argument. And that there are cases that may have many parameters, but use even few arguments (in languages that have optional arguments).
Related: How many parameters a method should have?
– Piovezan
@Piovezan Vish, I don’t know if it’s related or duplicated now, huh!
– Wallace Maxters
Mine is object-oriented, yours seems not :)
– Piovezan
@Piovezan but function and method are almost the same thing (I said almost). So I’m talking that it’s quite capable of being duplicated
– Wallace Maxters
@Wallacemaxters I do not consider as duplicate. Arguments passed via
this
changes the situation somewhat– Jefferson Quesado