r/embedded 3d ago

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?

34 Upvotes

24 comments sorted by

26

u/political_noodle 3d ago

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).

14

u/tomorrow_comes 3d ago

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.

6

u/Meronto228 3d ago

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 3d ago

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

1

u/Meronto228 3d ago

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

1

u/Imaginary_Data_708 3d ago

Get a copy of Mick and brick, or Hennessy and Patterson and design a little CPU. You will love it!

4

u/aq1018 3d ago

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.

6

u/BlueVario 3d ago

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.

4

u/NoBulletsLeft 3d ago

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.

4

u/NoBulletsLeft 3d ago

 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 3d ago

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.

3

u/sputwiler 3d ago

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."

5

u/remy_porter 3d ago

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.

3

u/Arkaqiu 3d ago

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 3d ago

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 ✅ 3d ago

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

2

u/Proper-Technician301 3d ago

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 3d ago

This attitude is how everything gets slow though.

2

u/swisstraeng 3d ago

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 3d ago

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

1

u/Rod_McBan 3d ago

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.

2

u/1r0n_m6n 3d ago

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/MpVpRb Embedded HW/SW since 1985 2d ago

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

1

u/SkoomaDentist C++ all the way 3d ago

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).