2 ms·
Not only that, but when you save something to a variable the reader needs to remember it in case you use that variable later again. For me personally that's exh
by TrianguloY 2y ago
Not only that, but when you save something to a variable the reader needs to remember it in case you use that variable later again. For me personally that's exhausting.
I've seen streams-like code with a variable for almost every step, immediately used the line below. I can understand when the reason is to "explain" the meaning of the intermediate step...but even so a comment is far better on my opinion.
I always try to inline every 1-use variable/method, unless there is a good reason for not doing so.
- InitialLastName 2y agoI feel like Raymond Hettinger's guideline that line complexity should be scaled to the limitations of human working memory, so should be limited to 7(+/-2) tokens [0], is a good compromise. This leaves some margin for nesting, but keeps in mind the capacity of the human brain to understand what a line is doing. If you can explain what the line of code is doing in a single sentence, you can probably also find a way to either name the variable sensibly or factor the code so that your step is a (well-named) method instead. [0] https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus...