Hacker News new | ask | show | jobs
by veli_joza 3333 days ago
Nice article. Some good insights, as well as beginner how-to steps.

The embedded industry has proven to be very resistant to innovations and modern code-writing practices. Some platforms I coded for didn't even support/allow C99 standard. C++ is gaining some foothold (mbed, for example). Developers don't feel the urge to catch on with times, like in other industries. And yet, now they are expected to write secure IoT systems.

Hopefully Rust can demonstrate its worth and convert key industry specialists who would blog about it. Personally, I'm still waiting for perfect opportunity to apply it on medium-sized project before I fully commit (secretly I'm still rooting for Nim).

2 comments

"The embedded industry has proven to be very resistant to innovations and modern code-writing practices .... And yet, now they are expected to write secure IoT systems."

Those are opposing goals.

I second that. Conservative nature of embedded industry led to lots of investment into things like static analysis, WCET's, and automated testing of few languages or platforms they use. Embedded is one of few sectors that can benefit from most deliverables in high-assurance field as well since they structure their stuff simple enough for that vs piles of Linux, containers, bloated apps, etc. The innovation happens outside of the coding mostly. That's why the coding keeps the quality that engineers intended to put into it. :)
It was my understanding that C++ was being abandoned in the embedded world in favor of C due to the failure of UML. See for example, the intro of this (possibly outdated) article: http://embeddedgurus.com/state-space/2008/01/object-based-pr...

Is this changing now?

I don't think that article is particularly outdated. The subsequent development of and cost drops for ARM Cortex-M processors has changed the scene a bit - but they had ARM V7 TDMI units then which were comparable.

But at no time has UML tooling been the driving factor behind the industry's adoption or lack of adoption of a language.

The problem with C++ and other high-level languages has always been that it's hard to see how much a line of code costs. Incrementing a pointer to an array in C has a transparent, short runtime, compared to moving to the next element in a C++ collection which may accidentally invoke a dizzying indecipherable mess of template objects, overloaded operators, and STL dependencies. Or in other languages, you may need a large operating system and runtime to be loaded.

High level languages do handy magic things for you under the hood. If your engine bay is measured in terabytes of storage, gigabytes of RAM, gigaflops of computational power, hundreds of watts of electrical​ power, and seconds of acceptable interaction time, those magic things that let programmers build useful features faster are nice.

But when you're trying to get guaranteed responses in microseconds from milliwatts of electrical power in a few kilobytes of RAM, you're likely going to be hand-picking everything under the hood. No magic allowed.

I didn't glean that the author is implying UML influenced language choice, just that UML vendors tried to sell to C developers.

But to answer your question, C++ is gaining a larger foothold in embedded if anything. More and more libraries are written in C++, and it's becoming more supported in the various toolchains.

From a very recent hackaday article - "Modern C++ allows us to write cleaner, more concise code, and make the code we write more reusable. The following are [...] new features of C++ that don’t add memory overhead, reduce speed, or increase size because they’re all handled by the compiler [...] after reading this you’ll be more aware of the newer features as we start to see them roll out in Arduino code."

http://hackaday.com/2017/05/05/using-modern-c-techniques-wit...

And also, because I was poking around their github today, here is Flybrix's source code, a lego-drone startup writing C++ on a Kinetis K-20 microcontroller (100 MHz ARM Cortex-M4). They use the teensy bootloader, which is why you see a mix of Arduino and C++ files

https://github.com/flybrix

Embedded C++ has been a thing for a while. The bigger issue is that one of the major compiler vendors only provides pre-standard C++ with no namespace std. C++11 is a pipe dream if you can't switch to a modern compiler. Still good enough for C with classes.