Small Functions
Last updated
Was this helpful?
Last updated
Was this helpful?
The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.
Decades of evidence say that routines of such length (>100 lines) are no more error prone than shorter routines. Let issues such as the routine's cohesion, number of decision points, number of comments needed to explain the routine, and other complexity-related considerations dictate the length of the routine rather than imposing a length restriction per se. That said, if you want to write routines longer than about 200 lines, be careful.
Treatment to long functions: