EMBEDDED TECHNOLOGY
The challenges of legacy code in embedded software development
By Colin Bigg, Perforce M
ost embedded software development teams will need to use legacy code at or because it is more convenient than migrating to something newer. The problem is that it may not be obvious what a piece of legacy code does, which may require effort to understand and new tests written to verify it still works as expected. Even when background information and tests still exist, practices or comply with functional safety or security standards.
integrate into other systems, adapt to use newer data formats or deploy to modern platforms and cloud-hosted environments. Security updates and patches may no longer be provided for the code and the vendor or community knowledge may have dwindled or disappeared. However, if using legacy code is unavoidable, here is some best practice advice: Test the code: create characterisation and unit tests and use code quality tools, such as a static code analyser, to understand what the code does and reveal any issues around function, performance, security and compliance to coding standards. Review documentation: examine original requirements and functionality to understand where the code came from and how it currently works. Identify any gaps that might not meet the new intended use. Only rewrite necessary code: while tempting, it is dangerous to rewrite an entire inherited codebase because it takes time and, without complete knowledge, could introduce bugs or dependency issues. It is better to take a selective approach to rewriting code.
Refactor legacy code: a more practical option is refactoring, performed gradually, whereby the structure of the code is changed but without affecting its functionality or altering its external behaviour. Refactoring also leads to ‘clean’ code that is easier to understand and maintain and less error-prone.
Make changes in different review cycles: avoid making too many changes at
“
Legacy code can integrate into other systems, adapt to use newer data formats or deploy to modern platforms and cloud- hosted environments.
and its own comprehension. However, AI is improving all the time, so it is worth experimenting with, for instance, large language models (LLMs), but backed by human interpretation and expertise. Lean on further research: some excellent resources are available, such as books written by Michael C Feathers and Martin Fowler about legacy code and techniques such as refactoring.
once. Otherwise, everything can become unnecessarily complex to manage, test and them more obvious to a reviewer rather than a sea of changes.
Collaborate with other developers: while not all team members may have worth encouraging collaboration within a team, helping to share knowledge about the codebase while reducing time and effort. Plus, a second pair of eyes is always a good idea.
Keep new code clean: for instance, adhering to the company’s coding best practices and compliance with appropriate coding standards. Consider AI: to speed up processes, but with some caution. AI can quickly rewrite legacy code but might introduce functional changes depending on how it was trained
”
Finally, avoid issues of maintaining legacy code in the future: when creating or updating code, for example, through using widely accepted coding standards, creating better documented and commented code, using version control, for maintaining and tracking changes to a codebase, and automated continuous testing to ensure that code remains functional and reliable as changes are made over time. Vitally, follow code security best practices to minimise the risk of software being compromised over its lifetime, with the help of secure coding techniques, security testing and static analysis tools, such as Helix QAC and Klocwork from Perforce.
Legacy code reuse is unavoidable for many embedded software development teams but, by adopting some tried and tested techniques and tools, modern embedded projects that involve a mix of legacy and new code can maintain compliance to required safety and security standards.
https://www.perforce.com/
DECEMBER/JANUARY 2025 | ELECTRONICS FOR ENGINEERS 15
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46 |
Page 47 |
Page 48 |
Page 49 |
Page 50 |
Page 51 |
Page 52 |
Page 53 |
Page 54