you are viewing a single comment's thread
view the rest of the comments
[–] 42 points 1 year ago* (6 children)

Apart from the bias, that's just bad code. Since else if executes in order and only continues if the previous block is false, the double compare on ages is unnecessary. If age <= 18 is false, then the next line can just be, elif age <= 30. No need to check if it's also higher than 18.

This is first semester of coding and any junior dev worth a damn would write this better.

But also, it's racist, which is more important, but I can't pass up an opportunity to highlight how shitty AI is.

  • source
  • parent
  • hideshow 6 child comments
  • [–] 2 points 1 year ago (2 children)

    Regarding the "bad code". It's more readable though to keep the full limit for each elif case, which is most often way more important than performance, especially since than logic with the age can be easily optimized by any good compiler or runtime.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 1 year ago* (last edited 1 year ago) (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 1 year 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.

  • source
  • parent