Teen Programmers Unite  

  How to write programs larger than 100 lines
Introduction and Legible Coding | Solid Code, Handling Exceptions, and Style | Comments, planning, and tools
By RedX
Comments, planning, and tools

E. comments:

Comments can make parts of a program more easily readable. But don't put in any comments unless you are going to keep them up-to-date.

Write at the begining of each file at least what is in it and what external dependencies it has.

Give at the begin of each function a short explanation what the functions is about.

Use comments to explain what a certain calculation is.

Don't use comments to make unclear code more readable. Rather make the unclear code readable.

And don't write comments that simply repeat the code.


value = value + 1 ; add one to value

F. Planning:

First know what you're going to build. Write down what it will have to do. Then break this description up in modules, then split it up in routines and functions.

By planning it first, it will be easier to write the code for it, because then you can focus on smaller parts.

G. Tools:

Short: Know your tools; know what they can and can't do.


Know what your compiler can do. Know how it can optimize or help to find bugs.

Know your debugger. hunting down a bug can make a difference between a night's rest or a night full of stress.

Know your profiler: Don't optimize a function that is executed only once. Optimize those that are frequently called. Don't assume a function needs more speed; check it first. Don't optimize before it works.

The same goes for a whole series of other tools too.

H. Conclusion:

This is a short explanation on this subject. One of the sources that can give you a much deeper insight of this matter is Code Complete (see bibliography). This is one of the most important things to master, because it allows you to write useful, bug-free programs with parts that can be reused in later projects.

Plan your project. Write clear and solid code with style, and remember that you have to write your program to be read by a human who doesn't know what the project is about. The compiler will make it understandable for the computer. There is nothing that can make unclear code understandable for a human (except some tools to make a better layout).

I. bibliography:

Code Complete: A practical handbook of software construction.

Steve McConnel

Microsoft Press

ISBN: 1-55615-484-4

| Previous |
Copyright TPU 2002. See the Credits and About TPU for more information.