• ammonium@lemmy.world
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    2
    ·
    14 days ago

    A function which is only used once is code smell to me. A function with 200 lines of code and a few comments here and there which I can read from to to bottom can be much more readable than 20 10 line functions for which I have to jump back and forth.

    • 9point6@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      arrow-down
      1
      ·
      14 days ago

      A 200 line function tells me the code is very likely to be inadequately unit tested and/or is going to be fragile when it’s changed in the future.

      Functions aren’t only for code reuse, they are for structuring your code.

      • HereIAm@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        13 days ago

        I agree with 200 functions being bad, but breaking them up into private functions won’t help you with unit testing, unless you do the other sin of testing private functions. Sometimes you end up with large functions, but when you do it might be a good time to consider creating a new class to spread the responsibilities a bit.

      • ammonium@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        13 days ago

        In my experience function calls are mostly for breaking my flow of reading. I don’t see why you couldn’t add structure with newlines and comments.

        It could be that I’ve only seen bad code and if you do it good it actually improves readability. But I think there’s more chance I’ll encounter a unicorn than good code.