Wednesday, April 13, 2011

6 Guidelines For Programming

6 Essential Guidelines for Programming

1.) Learn your subject
2.) Make a game plan
3.) Keep you API open in the background
4.) Break the program up into manageable pieces
5.) Name your variables meaningfully
6.) Debug and thoroughly test your program for loopholes and bugs

1.) Learn your subject
How can you go half-assed into a project? You can't. If you want to make a really good application, then you must know what you are going for as a final result. Sit down and learn the ins and outs of the process you are replicating. For example, let's say you are making a mortgage calculator--Shouldn't you understand how the formula works before sitting down to slap together some code that probably won't work?

2.) Make a game plan
After you understand the subject, draw out your program's structure on a white board or paper. Not only will this give you a direction of travel, but also a reference to look back on while coding. Being able to look back on your ideas that are listed in a single location is extremely beneficial in the long run. Lots of beginning programmers tend to skip this step and don't make it in the real world where programs are thousands of lines long.

3.) Keep you API open in the background

The best reference you have at your disposal is the programming language's API. It explains how all the thousands of classes and methods provided work. These are the tools that you will need to build your program. For example, in Java, let's say I have a String. How do I know all the methods associated with the String class? You would open the API and scroll down to "String", where there is a list of every single method. You see, programming isn't about remembering every trick in the book--It's about knowing where to find the relevant information.

4.) Break the program up into manageable pieces

This is probably the most important tip! So take note! You aren't going to produce a program that works perfectly on your first attempt. The best way to attack large projects is to get one piece of the puzzle to work at a time. Take it slow and build it up--In the end, you'll have a functional program. =)

5.) Name your variables meaningfully

Since the last tip was the most important, this one cures my biggest peeve. NAME YOUR VARIABLES! Is "int x" or "int mortgageRate" more descriptive? Let's face it, if you leave your program sitting for a few months then come back to modify something, chances are that you won't know what the heck is going on unless the code explains itself.

6.) Debug and thoroughly test your program for loopholes and bugs

After you think you're done, you're probably wrong. A program requires rigorous testing in order to perfect it. What if someone enters a letter instead of a number for a calculation? How will the program handle it? It has two choices: crash or react to the bad input with some modifications that you have written. In the real world, if the program crashes and you don't care to modify it, you'll be fired!

Following these few guidelines makes programming in any language much less tedious and time consuming, making you into a more productive individual.

No comments:

Post a Comment