• EskueroA
    link
    fedilink
    arrow-up
    3
    ·
    11 months ago

    Damm I think I might do some bulldozing sometimes, but is fair game when splitting into a different file for organization?

    • luciole@beehaw.org
      link
      fedilink
      arrow-up
      8
      ·
      11 months ago

      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.

      • Phoenix [she/they]@beehaw.org
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        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.