Top tips for programming in any language

 

The points mentioned below are those that we have found to be the most important to consider when coding.
Of course they are subjective, and may not be applicable to your application.

Document your code

Hopefully your hard work will pay off, and your code will be used for years and years.
That naturally means that on-going maintenance and improvement will be required. Quite often that means that will be done by someone other than the original author.
Documenting your code, to summarise the purpose of a method as well as in-method comments to explain specific logic, is therefore paramount.
Returning to a piece of code, and having to reverse-engineer it to recall why it was written, is at best time-consuming.
The more complex the algorithm, the more textual explanation is needed.

Keep the documentation up-to-date

Changing the logic and/or meaning of a piece of code is common when improving your code base.
If the documentation is not changed accordingly, it becomes dangerously mis-leading later on.

Name methods, parameters and variables appropriately

Much of the meaning of a method can be conveyed by its name and the names of its parameters.
This is one way by which the amount of comments in the code may be reduced, and again benefits understanding the logic at a later date.

Use a consistent coding style

Coding standards differ from person to person and from organisation to organisation.
Whatever style you adopt, it is beneficial to keep the style consistent (at the very least across a project).

Use pre-existing libraries when appropriate

Don't reinvent the wheel if there is a library of suitable functionality available.
Many open-source libraries have a wide user base, and that means that they will be stable (or at the very least have problems fixed in a short space of time). They are also often free to use.
Bear in mind that introducing dependencies increases the complexity of your code management, and deployment.
Therefore, strive to strike a balance when considering the use of libraries.