In
the rush to get a product out the door, programmers often ignore code
maintenance — a key aspect of application development. For applications with
short lives, this rush may not pose a significant problem because once
deployed, no one will touch the code again. Embedded systems applications,
however, may have lives that span decades, and early coding mistakes can result
in significant bug-fix and update costs later on.
You must consider code maintenance during
design and implementation of software for an embedded application that will
have a long life. The following ten tips do not constitute a complete list, but
they address common issues that can give the team that maintains your
application cause to curse your name. And you may be part of that team:
1. Avoid assembly
code.
On a
low-end PIC microcontroller (MCU), you have no choice but to use assembly
language, and on a high-end ARM processor you probably do not need it. Between
those processor extremes, many programmers may use assembly language to
increase performance and to reduce code size. But using assembly-language code
can derail your project and set it back months.
Assembly
language lets you directly access a machine’s functions, but the difficulty of
understanding just what happens in assembly language code can overshadow the
performance gains you hope to achieve. For this reason, people developed
higher-level languages such as C and Java. Always treat assembly language code
with suspicion, because it can easily violate the “safety” features built into
higher-level languages.
If
you must use assembly language, include verbose comments that will save time
and reduce frustration when someone examines your code. Use comment blocks of
assembly-language code that include no more than five or six instructions. Ideally,
use pseudo-code in comments to describe the operation of an algorithm.