Truly Awful Code

So, on the back of my previous post about people designing applications for mobile devices having never even used one, I am now working for an employer who would appear to have never read any guides on how to code in Objective C – or any kind of language for that matter.

We’ll start with this simple bit of code that is not only written badly, it also contains 2 errors! ¬†Assuming this person had any schooling, I think they missed the classes on “else if”, “switch statements”, “enumeration” and “top down programming”.

[sourcecode lang=”c”]
if (yourScore < 12) { gameState = 1; } if (yourScore > 12) {
gameState = 2;
}
if (yourScore > 24) {
gameState = 3;
}
if (yourScore > 37) {
gameState = 4;
}
if (yourScore > 49) {
gameState = 5;
}
if (yourScore > 62) {
gameState = 6;
}
if (yourScore > 74) {
gameState = 7;
}
if (yourScore > 87) {
gameState = 8;
}
if (yourScore == 100) {
gameState = 10;
}
[/sourcecode]

The two errors are:

  • How does one achieve game state 9
  • And what if a persons score == 12

Continue reading Truly Awful Code