4 ms·
I thought this as well when I was reading it. I think what the article is suggesting, though, is not just that the subroutines would be "reusable" as in useful
by angusgr 17y ago
I thought this as well when I was reading it.
I think what the article is suggesting, though, is not just that the subroutines would be "reusable" as in useful if called from another part of the program.
He's suggesting that the contents of each subroutine should be decoupled from each other - so not sharing global state, depending on strange changes made in other seemingly unrelated methods, etc.
The property of "I could reuse this routine if I needed to" implies low cohesion and therefore (probably) more maintainable code.
Steve Yegge argued something related to this topic that I don't think I like much, and I don't think you'd agree with it either. He claimed that junior programmers tend to write shorter methods because they're not used to fitting large chunks of complex code in their heads:
http://steve-yegge.blogspot.com/2008/02/portrait-of-n00b.html http://steve-yegge.blogspot.com/2008/02/portrait-of-n00b.htm...
As someone who has seen 2000-line long C++ methods written by "senior developers", I still think short clearly named methods are better. :)
- jonke 17y agoI have seen Fortran programs that don't have any subroutine at all //senior guru model. Even if you could reason about that large amount (40K LOC) I don't enjoy when you die and I get the responsibility to fix "the bug". I do agree that you should not (depending on language) write sub of everything. ex int add(int a, int b) {return a+b;} //Junior model