The Do’s and Don’ts of Writing Code

Every programmer has their own coding style. It is similar to your handwriting, it can sometimes be illegible. Here are some tips for beginner programmers, and some reminders for the experienced, to keep your code clean and pleasant to the eye.

  • DO diligently comment your code. Make sure you have a decent header, that includes the author’s name, date of last edit, and a general description of what your program does and how to run it. Comments should be straight forward, so that you, and other people, can understand.
  • DON’T be allergic to commenting. The most common excuse is that commenting takes up time. Take the extra seconds to comment as you code, and you won’t be regretting it later when you test and debug hundreds of lines of code.
  • DO make variable names simple. Use short names that are easy to understand and straight to the point. For example, Lname, for “first name”.
  • DON’T be abstract. No, I’m not talking about Abstraction, but rather in regards to naming variables, functions and methods. Do not use long names that include a lot of different symbols and/or a mix of upper/lower case letters. For example, a poor function name for adding two integers, “Add2Integers”.
  •  DO, stay consistent. I have heard this many times before, “there are two kinds of programmers in the world…”

these ones:                                                                         and those ones:

functionName(){                                                              functionName()

body…                                                                                  {

}                                                                                              body…


If you don’t see what I mean, in the above example, it’s OK, you will eventually! Honestly, it doesn’t matter which kind of programmer you are, as long as you choose one format, and stick to it.

  • DON’T be all over the place. This is one thing that sticks out to programmers. Keep a constant flow of style and sick to the same format with any program you write. I personally use the same format as the right side example shown above. I find it easier to match up the {}, especially if the editor you use doesn’t line them up for you!

Share additional tips below, in the comments!




2 thoughts on “The Do’s and Don’ts of Writing Code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s