I have often come to realize that to become better at something you first have to know that something exists. As an example before I started working with a microprocessor I had no idea what it could do. I heard of running LEDs with it, but it hardly seemed that powerful. After having a class directly working with the Tiva Launchpad and us implementing our own libraries for a daughter board I was quite surprised by the power of a microprocessor. Once I knew what the thing could do it greatly expanded a number of projects I thought I could work on.
Now, this class and a couple of others gave me a decent background in working in different programming approaches. However, I came across a variety of programming methods, etiquette, and conventions. All of this information seems passed on through example rather than being told in some tutorial. I have tried tutorials, but several only ever focus on technical details rather than simply having good programming practices.
Therefore, I was interested in asking what good programming practices you think are worth taking note of. I can list a few examples of what I have learned.
-Code readability: I believe you should be able to give someone your project files to someone and they can completely understand the project without saying a word to them. This would include things from your programming structure (all functions in a single file or across many), descriptive variable/function names, commenting on arguments and purpose, commenting on algorithm heavy sections, etc.
Sticking to a particular style. For example, I have done away with tab indenting and stick with manual 3 or 4 spaces per nested portions. Or I use //**** (80 characters) ***** to highlight the differences between all functions to more quickly navigate through my own code. Coding within 80 characters.
-Design Structure: The method I find I like the most I have come across is the idea to divide your project into several pieces to more easily navigate and plan the project. Usually, the more the better. For example, recently I implemented an alarm clock. My setup() called a boardInit() function (which had its own short library) which called 4 other initialization functions for push buttons, 7-segment displays, and a piezo buzzer. These each had their own designed libraries. In which case, the loop() function did only three things. It looked to enter three different states of "set the alarm", "count down", and "entering an alarm state".
-Removing Errors: The idea to make sure you scan for as many errors in a function as possible. If a function has 3 arguments each argument should be scanned for potential error (if possible) and the function should return something to indicate success or failure of the function. Each function call should be scanned for error as well. This greatly helps in troubleshooting. However, implementing becomes tedious.
Is there anything else you have come across which is good programming practice?