A great programmer makes their code clear, robust, efficient, and user-friendly.
Code needs to be clear so others can read and understand your code.
Code needs to be robust to reduce the number of errors in your program.
Code needs to be efficient to reduce the cost of your code.
Code needs to be user-friendly so that people will want to use your program.
Here are some Do’s and Don’ts that will guide you to becoming a better programmer. Bad style will cost your grade so keep these in mind and think of your own as well.
- Comment your code concisely
- Give your variables and functions good names for clarity
- End your phrases with semi-colons
- Indent your code properly
- Include your name, andrew ID, and section on the top of your code
- Have more than 80 characters in a line.
- Have dead code (code that does nothing, or commented out code)
- Use meaningless variable names
- Use magic numbers (numbers that come out of nowhere)
- Add too many comments, or redundant comments.
Here is a comparison of good and terrible code. If you can’t differentiate the two, ask for assistance as soon as possible.