No matter how wide spread and common place I believe embedded software best practices are, I continually come up against engineers and companies that are either just getting started or in such a frenzy that the basics get thrown out the window. Here are some basic best practices to keep in mind no matter how frantic and crazy the development cycle gets.
- Break application up into small manageable pieces
- Encapsulate and manage variable scope
- Limit the size of functions to no more than a single printed page
- Use descriptive naming conventions
- Never write clever code only functional and readable code
- Always null terminate strings!
- Make sure that you properly initialize all pointers and arrays with known values
- Don’t create more than one level of dereference by avoiding pointers to pointers.
- Bound pointers to a region of memory and check them constantly
- Remember that arrays are NOT pointers
- Keep functions to a cyclomatic complexity less than 10
- Always check that a function pointer is not NULL before executing
- Make configuring assert one of the first things you do when creating a project
- At least 25% of the lines of code should be comments