←back to thread

11 points dacsson | 1 comments | | HN request time: 0.269s | source

I know that ~70% of embedded systems are programmed with C, lots of movement or at least motivation is seen on moving to Rust. My question is: why this languages are good for embedded software development? And overall what would constitute a good PL for this domain?
1. Flundstrom2 ◴[] No.43730722[source]
Depending on size of the embedded system, the preconditions differs slighly; An Android phone is an embedded system, just like an 8051.

Android programs (and lots of Android itself) is written in Java, giving it memory safety, strong typing and ease of programming.

But it comes at the cost of garbage collection, requiring JIT for performance and high RAM and Flash consumption.

Those drawbacks are acceptable for use apps (just buy a new phone every 2 years), but not in the low-level, such as the Linux kernel. And straight up impossible on an 8051.

C gives the performance and low footprint to work both in a Linux environment and 8051, but it comes with the drawback of no memory safety and a lot of footguns. Performance is not just about speed and RAM/Flash requirements, but also about en energy consumption and physical size of the MCU on the PCB - both of which are increasingly important.

Enter rust: The performance and low footprint of C, with the memory safety and strong typing of Java. The lack of garbage collector is compensated by a /very/ picky compiler that makes memory management a fist-class citizen. All those problems a C developer would manually have to manage, remember and hopefully cover, are enforced compile-time.

Analysis done in large C codebases have shown that roughly half of all security vulnerabilities reported simply cannot happen in Rust because the compiler don't allow it.

Some say Rust is harder to learn, and it's harder to program in. But that is because writing bug-free programs IS hard, and the language is designed to prevent a whole class of bugs without sacrificing performance or footprint.

I think, Rust is what C would have been, had C been invented now, rather than 50+ (!) years ago.

There are only a handful of languages that are efficient enough to be suitable for embedded systems, with C and C++ being the most common. But Rust is certainly one that is very well suited for the job.

And thanks to cargo, embassy and OSes like Ariel, there is a very big set of standardised APIs and crates that makes embedded development feel just as efficient as desktop or server development.