Hacker News new | ask | show | jobs
by caseymarquis 2466 days ago
Is there an article on this? I feel like I must be missing some context, as 5 lines seems short enough to be counter productive.
3 comments

Uncle Bob (writer of the Clean Code book) argues that functions should be small (3-10 lines long, and not longer). He brings up 2 points as far as I remember.

1 - functions are(should be) well named so anyone later on will have better understanding of the intent of the writer of the code.

2 - bugs have a harder time to hide in 5 lines of code than 30 or 300 lines of function code.

If you did not read it I recommend it or the video series based on the book.

I worked on only one code base where we more or less held ourselfs to this and the class length limit (classes really should not be more than 2-300 lines long) and it turned out pretty well.

I probably exaggerated a bit. This paraphrase says the limit is “hardly ever 20 lines”.

https://dzone.com/articles/rule-30-–-when-method-class-or

Sorry, don’t have the actual book at hand now. Still a great read though.

I think 5 lines is pretty short but good. At the very longest, I like a function to fit on one screen of text so I don't have to scroll to see the entire function.
I like to use curly brace jump shortcut and interactively debug my code and other's code to avoid being too picky about this stuff, unless you have to stick to 80x24 kernel surface ;P