| Have you read his books or just his tweets? 1-line methods is taking things to an extreme (though you can write a lot of logic into a single line in Ruby, so maybe it's not as crazy as it would be in C...) but I found the discussion in his refactoring book about reorganizing methods and naming things very illuminating. It's an idea so simple it sounds stupid sometimes to try to explain to people, and yet, I never stop seeing new code that could be improved by something as simple as methods with accurate names. E.g. I've seen a lot of stuff like: ``` // This does X [some obtuse nasty inline regex or five-layers-deep nested object call or otherwise crazy individual line of code] ``` That maybe eventually gets detached from that comment line and now there's just some nasty line that nobody on the team understands anymore that can't as-is be easily tested in isolation from a bunch of other stuff. A perfect opportunity for a one-line method, that can have a descriptive name and can have its own specific tests. And yeah, again, that's the extreme case, but most codebases have tons of opportunities for 5-10 line methods being extracted with helpful names. If you find yourself writing a comment to describe a block of code, maybe make that comment your method name instead. And sometimes you try it, and realize "wow, it's hard to extract these methods without an insane amount of input params and return values for each bit" and maybe that's an important thing to realize about the code you're looking at anyway. ;) |
> [some obtuse nasty inline regex or five-layers-deep nested object call or otherwise crazy individual line of code]
… which no longer does X