• BassTurd@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    2 days ago

    Code readability is important, but in this case I find it less readable. In every language I’ve studied, it’s always taught to imply the previous condition, and often times I hear or read that explicitly stated. When someone writes code that does things differently than the expectation, it can make it more confusing to read. It took me longer to interpret what was happening because what is written breaks from the norm.

    Past readability, this code is now more difficult to maintain. If you want to change one of the age ranges, the code has to be updated in two places rather than one. The changes aren’t difficult, but it would be easy to miss since this isn’t how elif should be written.

    Lastly, this block of code is now half as efficient. It takes twice as many compares to evaluate the condition. This isn’t a complicated block of code, so it’s negligible, but if this same practice were used in something like a game engine where that block loops continuously, the small inefficiencies can compound.

    • Lifter@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 day ago

      Good points! Keeping to the norm is very important for readability.

      I do disagree with the performance bit though. Again, there will probably be no difference at all in the performance because the redundant code is removed before (or during [e.g. JIT optimizations]) execution.