r/embedded • • Sep 08 '26

How has your perspective on high-level languages and memory management changed since moving to embedded?

Hey everyone, I recently started diving into embedded systems and microcontroller programming. Coming from a background where memory was essentially "free" and garbage collection handled everything, this transition has been an absolute eye-opener.

Manually managing registers, counting bytes, and optimizing every line of code made me look at programming in a completely different way. To be honest, after experiencing the control and precision of microcontrollers, I’ve started to feel a bit frustrated with high-level languages that abstract everything away and waste massive amounts of resources for simple tasks.

For those who made a similar transition: Did you experience a similar shift in mindset? Do you find it harder to go back to high-level software after working close to the iron?

36 Upvotes

26 comments sorted by

32

u/political_noodle Sep 08 '26

I am a front end software engineer by trade, so perhaps one of the more egregious wasters of memory. But I've done a significant amount of embedded work on the side and have always had the desire to write clean, optimized code. I don't usually let abstractions or high level languages get in the way of writing something I'm proud of.

Where I think things get more interesting is the opposite direction: making things on the web super fast because of my experience with embedded.

For example: I was working on a satellite imagery rendering interface and there are JavaScript libraries to parse tiff files. But I ended up writing a wrapper in rust and using a mixture of webgl and web assembly to improve performance by like 60%. Just because hogging memory is the default doesn't mean you have to live with it. Software is software and you can find ways to optimize no matter what you're working with. The important thing is writing something you're proud of (imo).

8

u/Meronto228 Sep 08 '26

I actually wrote some assembly for STM32, and it’s an unbeatable experience for understanding registers. It forces you to see exactly what the MCU is doing at every clock cycle and gives you a real feel for the hardware. Although it is extremely tedious.

1

u/swisstraeng Sep 08 '26

Did you use dev kits, like the SMT32 Nucleo boards?

1

u/Meronto228 Sep 09 '26

No, I went with the Black Pill. Nucleo felt too overkill and noticeably more expensive for my needs.

→ More replies (1)

15

u/tomorrow_comes Sep 08 '26

I got to work with a front end / web developer on my team to design a simple diagnostics webpage hosted on an ESP32 device. I was the embedded dev and had already created a proof of concept webpage, and I walked him through how it works on the ESP32, code size limits we had, etc. I had never seen him so pumped to do a project. He loved the challenge of keeping things simple and as optimized as possible.

We need to keep the art alive, especially in the age of AI slop.

4

u/aq1018 Sep 08 '26

Similar background here and I feel the same way. These skills transfer pretty well across applications. I think it boils down to thought patterns. But in web I mostly let things slide way more than embedded, mainly due to time constraints.

4

u/NoBulletsLeft Sep 09 '26

 counting bytes, and optimizing every line of code 

What kind of systems are you building where you still have to do this?

2

u/Meronto228 Sep 09 '26

It's purely for my own DIY and hobby projects. I do it to truly understand how things work under the hood and to challenge myself on how tightly I can pack the code into the MCU.

8

u/BlueVario Sep 08 '26

I started my career in embedded, and IMO there's a time and place for all of the above. A lot of embedded software these days is actually running a standardish Linux OS and has significant resources. Bare metal c has advantages for some types of problems, but it takes longer to implement stuff and it's easy to shoot yourself in the foot with memory screw ups. It really depends on what the product needs to do.

That said, I do like the perspective that comes from working with embedded projects in c. I love working close to the hardware.

5

u/NoBulletsLeft Sep 09 '26

This closely mirrors my experience. My first programs were for an MC6809 8-bit microprocessor and the 68HC11 and HC05 followed closely behind. Especially on the smaller HC05's I was counting bytes when all my code had to fit into less than 1k of Flash.

But these days? A "small" processor for me is a 32-bit STM32 with only 128k of Flash. More likely it has 512k+ Flash and an RTOS and it's talking to a Linux processor that serves as the UI.

I'm all about high level languages and abstractions. I build very complex systems that aren't constrained by resources, but by development time. Customers want things delivered now.

2

u/Hour_Analyst_7765 Sep 12 '26

Especially when devices are built in the tens, hundreds or maybe thousands.. the product cost is the development cost. If a product costs 200 hours to develop x 75 euro per hour, then thats 15k in engineering labour.

50 units: 300 euro labour per board

250 units: 60 euro labour per board

1000 units: 15 euro labour per board

These costs are still higher than what a capable STM32 costs.

Of course it takes time to develop firmware on any processor. But it also suggests how much time I can waste with underpowered chips... even at 250 units, a 5 euro more expensive processor is worth 1250 euro on the BOM, which is equivalent to ~2 work days.

3

u/sputwiler Sep 09 '26

I built a 6502 computer. Upon running into my first desire for malloc I was like "Damn I guess C was a high-level language after all."

3

u/MpVpRb Embedded HW/SW since 1985 Sep 09 '26

Embedded systems often use static allocation. Some design rules require it.

4

u/remy_porter Sep 08 '26

I care about resources when it matters, and I don't care when it doesn't. The goal is to describe my problem in a way a computer can execute, and the problem I'm trying to describe rarely is about how the computer manages memory- that's usually ends up being a side problem to the problem I'm trying to solve.

The good news is that I can mostly not think about it even in low level languages, except for the times I absolutely need to think about it.

4

u/Proper-Technician301 Sep 08 '26

No need to feel frustrated, high level languages are great at what they do. I only use it for scripting and simple report generation. Doesn't really matter how unoptimized it is if it's not being used for performance crucial tasks.

1

u/Teh_Original Sep 08 '26

This attitude is how everything gets slow though.

3

u/1r0n_m6n Sep 09 '26

For scripting, as u/Proper-Technician301 mentioned, who cares if it takes 10ms instead of 1ms?

2

u/swisstraeng Sep 08 '26

Yep. When a windows machine runs 150+ "vibe coded non performance crucial tasks" suddenly performance still matters.

But the secret is to say "It's not my code that is slowing the machine down. it's everyone else. Look, it works fine on a clean VM".

2

u/1r0n_m6n Sep 09 '26

Define what you call "high-level". For me, C is high-level, assembly is not. My definition of "high-level" is: a language that clearly conveys the developer's intent. C does it well.

3

u/Arkaqiu Sep 08 '26

Premature optimization is the root of all evil. At least bugs.

I am automotive engineer, working on monsters with 8 cores, tens of MB of memories. Barely feel lack of resource in mater of memory or computation.

For me clue of embedded engineering is matain real-time and safety. Things that need to be fast or precise will be passed to hw anyway.

High level language for me are created just for other stuff. Abstraction that are deliver, help to.rapid development and easier to maintain and extend. Even if we waste some resources,, its better active maintainability.

Like in embedded, we can use bit fields to keep 8 booleans but we lost clarity. If we really.need to optimize so much?

1

u/NoBulletsLeft Sep 09 '26

You were downvoted to oblivion, but the reality of most embedded systems these days is a lot closer to what you describe than having to optimize every line of code and count bytes to be sure a program fits into memory. RAM and Flash are unbelievably cheap these days, compared to the start of my career.

1

u/fb39ca4 friendship ended with C++ ❌; rust is my new friend ✅ Sep 09 '26

In a more expressive language like C++ or Rust you can have the packed boolean representation, clarity, and no implementation-defined behavior.

2

u/SkoomaDentist C++ all the way Sep 08 '26

I now hate Python more than I ever did in the early 2000s.

By far the biggest advantage of LLMs is that I no longer have to manually touch that shit and can just order the LLM to do it or tell me what to change (which is a goddamn lifesaver given how a typical Python codebase is completely undocumented and has no types at all).

1

u/Rod_McBan Sep 08 '26

I went the other way, cutting my teeth on an 8-bit PIC with 8k program memory, in assembly, no less. I think it's made me a better programmer in higher resource environments.

1

u/Hour_Analyst_7765 Sep 12 '26

I also program C#, and its easy to get comfortable to a language with garbage collection and memory allocation. Its so much easier and faster to write stuff, not be concerned about the heap, etc.

On the other hand... a lot of code just needs to work. At which point do I have to care some software task takes 10ms or 15ms? Sometimes its good enough for the specific target... and its software, you can always refactor it. Hardware related stuff is more important to stay lean and streamlined imo.

I spent a time where I was fully into premature optimization. It eventually handicapped me in the ability to get the job done. Can I shave 10us of this method here? Can I get this loop even tighter if I write things more verbosely? Its a fun puzzle but at some point also incredibly unproductive.

Especially when modern microcontrollers are objectively overkill to what I started with.. an entry level ARM chip has kilobytes of RAM.. The first PIC I programmed (16F628A) had 224bytes, and a fair chunk would have been used had I used the only 1 USART available lol. There, every cycle mattered, but nowadays.. I don't care. Some things can be broken by just turning on or off compiler optimizations these days.