5 ms·
Not only that, but in the last example in that section he replaces a fairly short and readable expression with a function call. I don't see how this is differen
by mrbrowning 13y ago
Not only that, but in the last example in that section he replaces a fairly short and readable expression with a function call. I don't see how this is different than a comment in any meaningful way (except that it requires extra lines of boilerplate and whitespace that don't lift any explanatory weight), and unlike a comment it pollutes the call stack for no good reason.
- hackinthebochs 13y agoThe call stack is cheap, its your mental stack that you should be trying to optimize for. Any label over a set of operations (even a single expression) will reduce the mental load necessary to understand an operation, assuming its reasonably named. Managing a stack is what computers are good at. Lets optimize our code for how we can better comprehend it--at a consistent level of abstraction with the fewest amount of level changes as possible.
- mrbrowning 13y agoOh, I wasn't trying to make a claim that this would result in any noticeable performance degradation in the vast majority of cases, but as a means of making code more understandable this particular example suffers in comparison to a comment: less code is on the screen, it requires the reader's eye to jump elsewhere, and again that particular expression is simple and about as easily understood as the function name that replaced it. I think we agree on what to prioritize in writing code, but I don't think that example in the article was a good demonstration of those priorities in practice.