by collyw · 13y ago · 0 comments
Should a "productive" one liner be put in a separate method / function with meaningful name, or better a comment beside it?
I personally find short methods often decrease code readability, as you constantly have to jump around, and can't read anything from top to bottom.
In general, if you have to jump into every method call to understand a method that calls other methods, the names are bad – probably too short and don't state intention.
Also, it can be harder to express the generator in a useful way in English than the code itself if the code is well written.
The purpose is to make the code as clearly self describing as possible. I would only do it if it made the code read more like a human language and remove too much complexity from one place.
But I put one-liners in a function when the one-liner is hard to read or too error prone (missing a detail won't lead to a compiler error, but to a bug).