I’m studying programming, and I don’t agree woth my teacher. She basically said that if we use break (and continue too maybe) our test is an instant fail. She’s reasoning is that it makes the code harder to read, and breaks the flow of it or something. (I didn’t get her yapping tbh)

I can’t understand why break would do anything of the sorts. I asked around and noone agreed with the teacher. So I came here. Is there a benefit to not using breaks or continues? And if you think she’s wrong, please explain why, briefly even. We do enough down talking on almost all teachers she doesn’t need more online.

  • Dave.@aussie.zone
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    11 months ago

    you’ll see that he doesn’t like functions to be very long. I think his rule is no more than 4 lines.

    Four line functions? Sounds like a codebase adhering to that rule would end up as a nice thick function soup. It feels like… I dunno, those database programmers that like normalising databases to the Nth degree.

    If you put your loops into functions then you can just use return instead of break.

    And that just sounds like abusing the concept of functions to replace standard flow control that your language provides.

    I mean, sure, if I find repetitive chunks of code popping up I’ll break them out into functions, but - generally speaking - I do functions that translate into discrete real-world or UI tasks. I’m opening and parsing a text file into internal structures, I’m doing the reverse to go back to a data file, I’m cycling through the data to update UI components, etc etc.

    But hey, I use C and on the rare occasion I sneak a goto in there, so I’m not qualified to pass too much judgement.

    • samus7070@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      11 months ago

      Yeah, it’s a bit on the extreme side for me. 10-20 is what I prefer. I find that if I follow that rule the code is easy to come back to later because the things a function does are more clearly defined. I can look at a higher level function and it’s filled with function calls like readX, createY and doThis. I don’t have to look at as many blocks of code and try to remember what the intent was.