For novel ideas about building embedded systems (both hardware and firmware), join the 35,000 engineers who subscribe to The Embedded Muse, a free biweekly newsletter. The Muse has no hype and no vendor PR. Click here to subscribe.

This month's giveaway is a Cypress CY8KIT-044 PSoC 4 M-series Pioneer kit. Enter here.

Published 8/21/2006

In a survey I recently conducted of my Embedded Muse newsletter subscribers ( ) I tried to understand who is using object oriented programming on their embedded designs. The data I've seen in the past is hardly believable, some polls suggesting over 60% of us use C++. That's logical for PC developers. but for embedded?

I think C++ scores highly because many of us employ C++ compilers to generate C code. Though using "//" to denote comments is great, it's hardly a mark of OOPiness.

My survey asked a different kind of question: "Please select all of the features of object-oriented programming (OOP) that you are personally using on your <i>current</i> embedded programming project." The 659 respondents replied:

34.7% Encapsulation
22.2% Inheritance
14.5% Polymorphism
63.7% None of the above

By correlating these figures against processor bus size the data becomes even clearer. 6.4% of respondents who work on systems smaller than 32 bits report using encapsulation. That makes sense, as encapsulation isn't restricted to OOP or OOPy languages. One can encapsulate in C and assembly as well. About 14% of 32/64 bit developers report using encapsulation but not the other features of OOP. That number is twice that for those working on smaller CPUs, perhaps indicating a more disciplined development strategy on these typically bigger projects. No doubt there's less legacy code as well.

33% of all developers working on 32/64 bit CPUs report using inheritance or polymorphism. Unsurprisingly, essentially everyone employing polymorphism also uses inheritance.

Though C++ offers many other resources, in my opinion inheritance it is such a fundamental part of that language's zeitgeist that it's a pretty good indicator of the spread of OOP into embedded systems. In an informal poll I ran five years ago the number of developers using inheritance was about half of the current numbers. which pretty strongly correlated with the increasing adoption of 32 bit processors.

Fourteen respondents complained of problems with performance and code bloat, which they attributed to OOP. These were unprompted emails triggered by the survey, so aren't statistically meaningful, no matter how interesting.

Are you using OOP in your embedded designs? Why or why not? Are you happy with the results?