Good clean code

I like good clean code.  More organization is better. More space is (usually) better.

If you are writing code, remember that the code needs to be readable by humans.  The compiler couldn’t care less what the code looks like, as long as it is syntactically correct.  It’s the poor humans who have to read your code that appreciate organized, easy to read content.

Here’s an example:

for(int i=lmt; i>=0; i--)
 {         sigbuf[i] = a*macbuf[i]+alpha_1*slbuf[i+1];   }

It’s syntactically correct, but, well, hard to read, to put it nicely.


for (int i=limit; i>=0; i--)
     SignalLineBuffer[i] = (alpha * MACDLineBuffer[i]) + (alpha_1 * SignalLineBuffer[i+1]);

Even if you don’t know what this code does, the second example is something you can easily see what the parts are.

The best book on this subject is Code Complete, by Steve McConnell.  Every programmer should have this book nearby.


Did you enjoy this article?
"Get my free programmer's checklist"
The checklist gives you step-by-step instructions on how to create the perfect automated trading system.

Leave a Reply

Your email address will not be published. Required fields are marked *