4 ms·
You might as well be able to extract a method with a meaningful name then.
by isbvhodnvemrwvn 5y ago
You might as well be able to extract a method with a meaningful name then.
- ziml77 5y agoPlease no. Don't extract methods methods just to avoid using a comment. You end up making code more difficult to follow when you do that since you're now jumping somewhere else in the file and you're adding a lot of noise by having to pass the function's current state along as arguments to the new function.
- hackinthebochs 5y ago>by having to pass the function's current state along as arguments to the new function. But then the state being read and mutated by a block of code is explicit. The alternative is having to inspect the code to determine if and what state is being manipulated. The more code in a functional unit, the harder this gets.
- nicoburns 5y agoIf you're mutating variables then I'd agree that it might be best to encapsulate that in a function. But I'd argue that except for performance sensitive code, that's bad practice. The vast majority of code I write has 95% immutable variables. So even in a large function they'll typically be at most one or two mutable variables to keep track of (and very often zero).
- nicoburns 5y agoThat then makes the code non-linear, which IMO makes it a lot less readable in most circumstances.
- isbvhodnvemrwvn 5y agoIt depends, if it needed a comment in the first place it likely was at a different (likely lower) level of abstraction than the rest of the code in that method.
- nicoburns 5y agoYes, but that doesn't mean it doesn't benefit from being inline. I love being able to skim over the paragraph-comments to get the big picture and then dip into the details without having to jump to another file / part of the file and lose my context.