3 ms·
A hard limit of 15 lines might be acceptable for a very high level language such as Prolog, but it seems too short for most other languages. That said, there's
by DonaldFisk 11y ago
A hard limit of 15 lines might be acceptable for a very high level language such as Prolog, but it seems too short for most other languages. That said, there's a limit to how much anyone can hold in your head (short term memory) at once, though. I've had to work on code where several C functions were around 500-1000 lines each. Is that acceptable?
They seemed to work (i.e. had no obvious deficiencies), but there's more to code quality than error rates. Functions should be readable, easily modifiable, testable, and in many cases reusable.
Apart from possibly initialization code and functions containing large switch statements, I limit function length in my own code to a screenful: more precisely, one sheet of A4 paper if printed. (60 lines, 80 columns.)
See also 10 Rules for Writing Safety Critical Code (http://spinroot.com/p10/ http://spinroot.com/p10/) Rule 4.