3 ms·
I agree entirely that this isn't anything new, I hope I didn't imply it was. This is simply my own reflection on how to improve my coding style. > "Every line
by davethedevguy 6y ago
I agree entirely that this isn't anything new, I hope I didn't imply it was. This is simply my own reflection on how to improve my coding style.
> "Every line of code can be hidden behind a function, is that productive, acceptable and lean?"
I've seen some advocate for that exact thing, but I certainly wouldn't go that far. I don't think we have to have one or the other, there's a middle ground in my opinion.
If the code requires a comment to explain it, then maybe a well-named method/function is a better option. If the code is obvious in its own right (looping over a collection to add 1 to everything, to use a dumb example) then I don't think abstracting it is justified.
I certainly don't have any objection to single-line functions to add readability per-se.
(with the caveat that a compiler would produce the same result either way, or otherwise the performance of another function call isn't an concern. I'm talking purely about readability here)