You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »



Writing code can sometimes be the most difficult part of any project. If you don’t organize everything from the start – especially for big projects — the coding processes and code management afterwards may end up not just time consuming, but also a big headache.

Good code is maintainable, reusable, and testable. The following tips address how you can approach different coding tasks and how to keep everything as neat as possible.

Page content

Plan your coding

When starting up a big project or an advanced function, having a pre-made plan will often save you a lot of time. Even though everything seems clear at first, you may have forgotten or will forget something crucial while writing.

A good plan should contain information about your coding approach, when the different variables are known and unknown, and what the output of each code block is supposed to be. Knowing all this information in advance will help you locate difficult sections of your code, as well as preventing unnecessary code or rewriting.


Write useful comments

Commenting while writing will always help you out in the long run. Your code may seem very simple and self explanatory at the time of writing, but to someone else, or yourself in three months, it is not necessarily that simple. Write meaningful, single line comments for vague lines, and more detailed descriptions for more difficult sections. Also, remember to keep updating your comments when updating your code.

Use meaningful names

The name of a variable, class or function should in itself explain what it does and why it's there. If a name requires a comment, it does not reveal it's content. Take a look at the example below, which variable is easiest to interpret.

int d = 3600	# Seconds in one hour
# vs
int secInHour = 3600

Beware of names with very few differences, making them difficult to seperate.

int likesAtMDGFacebookPage
# vs
int likesAtMGPFacebookPage

Use pronounceable names.

char famousBlvd
# vs
char famousBoulevard
  • No labels