Ask HN: Maximum length within a control structure

  • According to Robert C. Martins book "Clean Code", and the SLAP principle, the maximum length of a method (yes, an entire method) is around 20 - 50 lines of code. If it gets longer than that, odds are that it is doing more than one thing and is operating on different levels of abstraction, and should be broken up into smaller methods. I would also say that I have rarely seen (if ever) well-written, easy to comprehend and maintain code where the control structures and methods contain hundreds of lines of code.

  • I would say that if you can't fit a function onto your screen, it's too long and should be broken up.