Transforming the Code

About half of Martin Fowler’s book is a catalog of refactorings. Each refactoring has a name, a problem that it solves, and a series of detailed steps that guide you through a code transformation. Fowler uses Java in his examples, but there is still plenty of useful advice for embedded C programmers.

To give you the feel of refactoring, we’ll refactor a long function. As we refactor, I’ll introduce some helpful techniques and a guiding principle.

Like in the real world, most of your time will be spent extracting functions from long functions. Aside from Rename, Extract Function is the most often used refactoring. Extracting functions reveals the work the long function is doing, raising its level of abstraction. In ...

Get Test Driven Development for Embedded C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.