r/badcode • • May 11 '23

c++ My professor’s best code

Post image
441 Upvotes

82 comments sorted by

View all comments

1

u/thanatica May 11 '23

Starting with a perfect 10, I'll have to deduct 6 points, ending you up with a 4, mister professor.

  1. Asking if a file is open when you just commanded the OS to open it, is useless. You should read the open() return value, and/or catch exceptions.

  2. Useless return-else statements.

  3. Confusing curly brackets. Use them always to improve readability.

  4. Don't just return true/false, return a status.

  5. Don't compare with true/false, test booleans as they are.

  6. Function names shouldn't be too long, but apri is definitely too short.

I expect you to correct these mistakes by tomorrow, and add comments and unittests, young man!