this post was submitted on 26 Jul 2023
10 points (100.0% liked)

Programming

13269 readers
2 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 4 points 11 months ago (1 children)

Yeah I don't agree with "bulldozer code" bit. Splitting a long function into smaller parts doesn't have to be about reuse. It's useful to do it for clarity. As a single function grows, the number of local variable often grows as well and eventually you end up juggling tons of variables and the slightest change ripples three hundred lines further down. Break it down into a handful of steps with a number of arguments you can count on your fingers and it suddenly becomes so simple. Same about deep nesting of loops/conditions.

Rule of thumb is a function needs to fit in my head - so if I stick my face on the screen and the function's code can still be partly seen, it's time to break it down.

[โ€“] [email protected] 0 points 11 months ago* (last edited 11 months ago)

The main thing I encourage here is: If you're breaking up longer functions into more smaller ones that are really only used in this context, don't mix them into the same file as functions that are general use. It makes code super confusing to navigate. Speaking from experience on an open source project I contribute to.