You've probably been told before that you need to write readable code. Being able to write a good, readable program can help your academic, professional, and (who knows?) maybe even your social life. If you follow these coding style tips, you'll be writing crisp, readable code in no time!
The typical compiler will spend only a few milliseconds reading your code. For this reason, the first few lines must hook the computer, and pique its interest. Lazy programmers often begin a file with the standard procedure:
This introduction, while correct, is downright boring. The computer will quickly get tired of your code and open something more interesting, like the latest Quake patch. You can add zest to your writing by including certain keywords:
int main(int Monica, char* Lewinsky);
int main(int OvalOffice, char* Cigars);
A lot of programs have a great function declaration, but fail when it comes to the function body. You have the compiler's attention; now you have to hang onto it! Look at the following code fragments. Which do you think is more interesting?
Tuition *= 1.50;
//That'll teach them!
When the compiler finishes reading your code, you'll want to leave a good impression. A good conclusion can make the difference between a successfully running program and an "ERROR 4: Tried to parse past end of file." Most conclusions contain three major elements, and it may take several revisions before you can combine the 'return', ';', and '}' in just the right way. But if you put them in a thoughtful order, the compiler will feel refreshed after reading your program.
The art of coding is just like any other art; it requires practice. If you use these simple coding tips on your next assignment, your prof will find it both more interesting and readable. Just don't tell them where you learned it, okay?