5 ms·
For me, aiming for the shortest possible methods and classes forces me to more carefully consider good design principles like Single Responsibility. I don't aut
by derrickdirge 11y ago
For me, aiming for the shortest possible methods and classes forces me to more carefully consider good design principles like Single Responsibility. I don't automatically assume that long methods are wrong, but they certainly smell.
- stonemetal 11y agoYes, but how long a method does it take to make you claim it is a smell? One of Steve McConnell's books lists a couple of studies that suggests optimal method length between 100 to 250 lines of code.
- derrickdirge 11y agoSmelliness generally increases proportional to length, simply by virtue of the fact that it takes longer for my human brain to parse. A one line function has no inherent smell because usually I can tell immediately if there's anything else smelly about it. A 250 line function smells a bit more since there are more places for more insidious smells to hide. Very short methods tend to be very easy to reason about. What properties of 100-250-line methods make them optimal?
- stonemetal 11y agoNumber of bugs per method.
- DonaldFisk 11y agoHow long ago were the studies made? One thing that's changed since then is the disappearance of continous form printing. Decades ago, you could print a 250 line function on four connected pages and lay them down on a table and see the entire function. Nowadays, reading printouts like that is unheard of.