Design News posted a great article “10 Questions to Consider When Reviewing Code” and I’m just posting the list here. Follow the link for the full article with the details behind each question.
- Does the Program build without warnings?
- Are there any blocking functions?
- Are there any potential infinite loops?
- Should this function parameter be a const?
- Is the code’s cyclomatic complexity less than 10?
- Has extern been limited with a liberal use of static?
- Do all if…else if… conditionals end with an else? And all switch statements have a default?
- Are assertions and/or input/output checks present?
- Are header guards present?
- Is floating point mathematics being used?
My personal pet peeve is #3 – I am constantly reviewing that uses WHILE loops waiting for a hardware bit to change state. But what if the hardware bit is broken? Then the device is DEAD. Always have some sort of timeout and use a FOR loop instead of a WHILE loop. At least the code will move on and won’t be dead. Maybe it won’t work properly because of the broken hardware but at least the device can limp along.