Rookie programmer mistakes you shouldn't be making

This article is a work-in-progress.

During my time at university I had the misfortune of helping out several fellow students with their code. The experience was never short of a few code smells, so I thought I'd take some time to enumerate some of them here, in hopes of improving student code in future. Note that I come from a C++ and C# background, but these points are largely applicable to other languages too.

Structure Problems

Muddy classes

asdf

Never write anything twice

If you find yourself duplicating your own code, you're probably doing it wrong.

Stringly typed data [1]

asdf. use enums.

Zero/One/Infinity

Things in a system should exist 0, 1, or N times, where N is variable. If you have more than one of something, the implementation should work the same regardless of how many items there are, and not impose any arbitrary numerical limits.

Never write anything twice

If you find yourself duplicating your own code, you're probably doing it wrong.

Semantic Problems

Brace style (and code style in general)

I'm not looking to start any flame wars here, so I won't advocate the use of one brace style over another, instead I'll simply say this: It doesn't matter. Pick the style that works for you and stick to it. Just please be consistent with your usage. Nobody wants to read inconsistent code - it just looks sloppy and it becomes hard to follow.

Indentation

Again, I'm not looking to start flame wars about personal style, but please indent your code consistently. Heck, a lot of IDEs will do this for you, and you don't have to worry about it. If your setup doesn't do this automatically (perhaps, god forbid, you're coding JavaScript in notepad.exe) then please take the time to manually indent things. It makes your code structure clearer, easier to read, and generally nicer to look at. It's also really useful for finding that missing mustache-bracket.

Single-letter variable names

Look, unless you're severely limited on disk space, you can afford to make your variable names a bit more verbose. Obviously there are some exceptions to this, a few of which are below, but generally your variable names should be descriptive.

  • i/j/k.. for loop variables
  • x/y/z for co-ordinates
  • e/ex for exceptions

Magic Numbers and Named Constants

asdf

Booleans

variable = something1 == something2 ? true : false;

Other Problems

Static and Nonstatic contexts

asdf

Version control

Bitbucket gives you infinite private repositories free for personal use. You have no excuse.

Memory management

Blarg.

File structure

multiple classes in one file, etc

Testing

fucking test your code.

Know how to ask for help

If you're asking a friend for help, tell them the exact issue, where it occurs or under what conditions, and if possible give them the exact error message. "It doesn't work" helps nobody.
XY Problem.