I always figured this was a nice joke but obviously not code that would ever actually be written by someone... Then I ran into this millimeter to inch conversion code in production this past month:
if (isNaN(mm)) return 0;
if (mm == 6) {
inch = 0.125;
}
else if (mm == 8) inch = 0.25;
else if (mm == 10) inch = 0.375;
else if (mm == 15) inch = 0.5;
else if (mm == 20) inch = 0.75;
else if (mm == 25) inch = 1;
else if (mm == 30) inch = 1.25;
else if (mm == 40) inch = 1.5;
else if (mm == 50) inch = 2;
else if (mm == 60) inch = 2.5;
else if (mm == 80) inch = 3;
else if (mm == 90) inch = 3.5;
else if (mm == 100) inch = 4;
...
That's terrible! Didn't we all learn that each method must have exactly one return statement? Please refactor to use a return variable and a single return. And get off my lawn!
I've actually seen this type of code produced by a human-being who was trying to write good code. It was one of the students in my introduction to programming class in university, we had to write a function that squared a number or something, and he had written hundreds of lines of if-statements. Sometimes you just use what you know to complete an assignment I guess 🤷
Apparently not. It was very strange. Although it was the first few days of class and he might not have realized * is multiplication, because when does a non-programmer ever use * for multiplication?