4 ms·
While I tend to agree with this, I think a counterargument is: long functions mean more local variables that are in scope. This makes it harder to understand t
by haberman 9y ago
While I tend to agree with this, I think a counterargument is: long functions mean more local variables that are in scope. This makes it harder to understand the interaction between different variables at different scopes. A separate function introduces a separate namespace, and all the data flow in and out has to be explicit, through function parameters/returns.
- vram22 9y agoYes, agreed about the counter-argument. See my nearby comment here: https://news.ycombinator.com/item?id=16064412 https://news.ycombinator.com/item?id=16064412 I think the important thing is that modularity (breaking up longer functions into shorter ones) helps, but only if not done blindly. One has to spend some time doing it, since there are many possible ways it can be done, and some of them will be better than others. So it can pay off in the long term, but only if one is willing to put in the effort and time, and be ready to throw away some not-so-good attempts. I've done this sometimes and seen that it does help.
- deleted 9y ago[deleted]
- Waterluvian 9y agoI would love an IDE that unrolls subroutine calls inline as a view mode.
- dec0dedab0de 9y agoThat is really interesting. They would have to be made to stand out somehow, but it might be helpful. I can only imagine what some library heavy code would look like.
- WaxProlix 9y agoPeek definition does this, sort of. Definitely exists in VS and VS Code, and probably in the JetBrains things.
- deleted 9y ago[deleted]
- meken 9y agoI'm working on this very thing right now as a side-project. It unrolls functions, if statements, for/while loops, etc and uses jupyter notebooks to do so AND allows you to interact with the result. Kind of like an interactive log. It's early days but I'm making progress! https://github.com/ebanner/pynt https://github.com/ebanner/pynt
- jeremiep 9y agoThat's not always true, the best cases for inlining one-use functions is when you don't introduce new local variables. I've seen 1k LoCs functions that were incredibly easy to understand, and 10 liners that were complete gibberish messes. I do however agree that declaring new variables every 10 lines over hundreds of lines would be hell to follow.