Comment on ChatGPT advises women to ask for lower salaries, study finds
Lifter@discuss.tchncs.de 1 day agoRegarding 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.
BassTurd@lemmy.world 21 hours ago
Code readability is important, but in this case I find it less. 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 dates ranges, the code has to be updated in two places rather than one. The changes are 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 2 hours 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.