nrg_alpha;10897646 wrote:WP, I'm not arguing the idea of creating clean, unified data structure, as this makes sense and good use of coding practices. What I am wondering is why the hard limit of 4 to 8 variables? (again, I like the idea of reduction in variable bloat.. don't get me wrong...) I can also definitly understand how one approaches the deisgn / creation of variables has an impact on things (and we know there are very good coders out there, and very poor ones, [<----- which I lump myself in the latter category, but I digress]).
I would gather that in real world applications (say some form of statistics by example), this imposed limit could easily be busted. Does this mean that the design in question is terrible? I would image not necessarily so. It can still be exceptionally well structured and organized, yet exceed this limit. This is what I was getting at.
I at least never said anything about a hard limit. It's perfectly possible to write programs in which no function takes more than one argument. But if you're having to pass a dozen or so arguments then it should be treated as a warning sign suggesting those problems cited may be affecting you.
Your bowling example, for example. You've got an array of all those results. By calculating all those summary statistics and passing piles of results to one function, you've introduced a very strong dependency between the calling function and the called function - to the extent that the latter one probably can't be used anywhere else and then you might as well skip having the function at all.
On the other hand you could just pass the original array to the function and have it calculate the statistics (by calling one function for each set, passing the array to each one in turn).
On the other hand, in an object-oriented environment, those would probably be properties of an object that contains the raw data and also caches those results as they're requested. Or if the data is stored in the database, then the place to calculate them would be in the database.
Remember, too, that we're not just talking about how many variables there are; we're talking about how many parameters a function has. imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) is getting a bit on the bulky side: the standard libraries of most OOP languages (Java, C#, C++) have "Point" and/or "Dimension" or at least subclassable "Pair" objects for storing pairs of coordinates, and if PHP was an OOP language with such a standard library the function signature would look like $dst_image->imagecopyresampled($src_image, $dst_corner, $src_corner, $dst_size, $src_size).