How to ensure clean programming code

Google+ Pinterest LinkedIn Tumblr +

Part 1 on “How to ensure clean programming code”

How can you keep your code clean? Updatable, readable, and alterable?

Here are some ways you can do it, saving time and aggravation later.

1. Take advantage of line spacing

Use new lines frequently, and keep the tab key in mind.

This will allow for nice indentaion and spacing for readablilty.

For blocks of code within “{}”, put each “{” or “}” on a seperate line.

You may also want to comment on what each one ends and begins.

2. Comment your code

Use the block and/or line comments your language provides you with.

This will let others understand your code, and most imporantly, you.

Short comments are the best, after every line, or more important code pieces.

Summarize blocks of code nicely, ensuring it is updateable without hassle.

3. Remove hardcoded variables

Hardcoded variables make code hard to understand. Instead of looping with

for(i=0;i>5;i++) to repeat 5 times for the width of something, make a simple variable

“width” and set it to 5 to make it understandable.

This will help you alter your code at a later time as well.

4. Give perfect code some reusability & efficiency

If you have a bit of code, a script or function, that you think is perfect,

check through it to make sure. Simply see if anything can be sped up,

or if a script/function can be made multi-usable. In other words,

make it support more things easily to make it as flexible as possible,

until you can find nothing else reasonable to add. Then you can use it

for other things later, without making all new code.

5. Code compression

One a script or function has everything in the 4 steps above, compress it.

Compress it only if it has nothing to be changed or edited, and you’re certain it

never will be. Remove spaces and line breaks to compress the code,

or use a code compression program. This will save you memory if memory

is something of an object for you.

These are the first 5 steps on making your code perfect.

Follow them, and your code will be far better.

I hope this helps.

-Exarmaster

Share.

About Author

Leave A Reply