To provide some more context around the advice for the ideal number of function arguments being zero in Robert Martin's "Clean Code: A Handbook of Agile Software Craftsmanship", the author says the following as one of his points:
Arguments are hard. They take a lot of conceptual power. That's why I
got rid of almost all of them from the example. Consider, for
instance, the StringBuffer in the example. We could have passed it
around as an argument rather than making it an instance variable, but
then our readers would have had to interpret it each time they saw it.
When you are reading the story told by the module, includeSetupPage()
is easier to understand than includeSetupPageInto(newPageContent). The
argument is at a different level of abstraction that the function name
and forces you to know a detail (in other words, StringBuffer) that
isn't particularly important at that point.
For his includeSetupPage() example above, here's a small snippet of his refactored "clean code" at the end of the chapter:
// *** NOTE: Commments are mine, not the author's ***
//
// Java example
public class SetupTeardownIncluder {
private StringBuffer newPageContent;
// [...] (skipped over 4 other instance variables and many very small functions)
// this is the zero-argument function in the example,
// which calls a method that eventually uses the StringBuffer instance variable
private void includeSetupPage() throws Exception {
include("SetUp", "-setup");
}
private void include(String pageName, String arg) throws Exception {
WikiPage inheritedPage = findInheritedPage(pageName);
if (inheritedPage != null) {
String pagePathName = getPathNameForPage(inheritedPage);
buildIncludeDirective(pagePathName, arg);
}
}
private void buildIncludeDirective(String pagePathName, String arg) {
newPageContent
.append("\n!include ")
.append(arg)
.append(" .")
.append(pagePathName)
.append("\n");
}
}
The author's "school of thought" argues for small classes, zero-argument functions, and very small functions. While I also don't agree with it fully like many here, I found it thought-provoking and I feel that the idea of zero function arguments can be worth considering.
(Also, as others have pointed out, he argues that more arguments make it harder from a testing point of view. But here I mainly wanted to highlight the above example and his rationale for zero function arguments.)