Good code will be reused over and over by many different programmers; this is a reason to keep your code neat and clean. Give your variables useful, meaningful names whenever possible (excluding iterators and temporary values). Your functions should also have meaningful names: "func" is not a good name, and chances are other programmers already use func in their code so this will cause conflicts. Be consistent, pick a style and stick to it.

Don't hesitate to add comments to your code . Make sure that your comments are useful. A comment like "// here we call this function" is not very helpful to a programmer who is trying to understand what your code actually does. When your main function grows to over 200 lines of code, it is time to review and read more about functions and begin to implement them in your code. Most importantly, read your own code before you show it to others, and make sure you show it to others for them to read. Code reviews save you time, effort and frustration.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement