6 ms·
It's a lot more than these two things, in fact I think these two things are not as important as the main benefit of smaller functions, which is making code that
by hellofunk 10y ago
It's a lot more than these two things, in fact I think these two things are not as important as the main benefit of smaller functions, which is making code that is easy to understand at a glance. Good naming with proper separation of logic into small pieces can make even c++ read almost like prose. It's hard to find, but when you see it, it always blows me over.
- mannykannot 10y agoWhile I do not disagree with Fowler's criterion as being one of several to consider, The ability of function (and identifier) naming to make code "easy to understand at a glance" is frequently overstated, including in this article. Once code reaches a size where it is moderately complicated, the reasons for some action being done in a particular way are not necessarily locally obvious (or obvious at all.) One common reason for this is that things are being done in a particular way to conform to a contract that is relied upon in multiple, disparate parts of the program (and any reasonably large program does have such contracts, even if it was not produced by an explicitly design-by-contract methodology.) For a flavor of how this works, read the article [1] below, in response to Tom Cargill's classic article 'Exception Handling: A False Sense of Security'. Even though the code example here is small enough to be understood in one go, I doubt that the reasons for it being the way it is are immediately obvious to most programmers, unless they have been primed by exposure to the issue before (note that the first answer given was not entirely correct.) [1] http://www.gotw.ca/gotw/008.htm http://www.gotw.ca/gotw/008.htm