Hacker News new | ask | show | jobs
by rahil627 456 days ago
some people hate to use C. Some people embrace it, even love it (including many game devs!). You have full control! But i wonder, what do HN folks think about these pico implementations of ruby, a complex language made for the tiniest devices, such as sensors? I mean.. is C really that bad??

also, it's very cool they're still being maintained!

4 comments

It is a return to the age when we had BASIC and Z80/6502 Assembly, and yes doing memcpy/strcpy all over the place instead of having proper arrays and strings is that bad.

At very least, C++.

"C++14 For The Commodore 64"

https://www.youtube.com/watch?v=nLv_INgaLq8

> doing memcpy/strcpy all over the place instead of having proper arrays and strings is that bad

This presupposes that you're doing string manipulation and raw memory moves. I don't know about other people's code, but in my own experience neither of those things are likely to be happening in embedded code. You're much more likely to pre-allocate all your memory, and use zero-copy patterns where ever possible. I never used a C-string in relation to talking to peripherals (i2c, spi, register mapped) or when doing dsp. Moreover, if you do need to use memcpy it's probably because you are doing something very low level for which memcpy is the best choice.

What is embedded nowadays was a home computer in 1980's, so maybe you aren't, as someone that started coding on a Timex 2068, I very much doubt that in general.

MISRA and similar exists for a reason.

I don't think C is bad at all. One good thing about C is that the language is quite minimal, the same can not be said for the current batch of contenders (Zig, Rust). Another good thing about C is that it has strong separation of language standard from implementations, with many implementations provided by diverse suppliers. I also prefer the "batteries not included" philosophy. Obviously C is not without warts (e.g. logical operators precedence).

I will leave it to others to fill out the cons. One obvious one is that C does not reflect the parallel compute nature of modern targets (e.g. SIMD) but neither do most serious alternatives.

I do think the time is coming (if not already here) where it would be judged legally negligent to professionally employ C in new systems for certain use-cases (network facing, high assurance, ...). At least not without complete formal verification. I'll leave it to the actuaries to work out where the tipping point is.

Make a few small mistakes, even typos, and C becomes really that bad, because you have full control, no restraints, few guard rails.

C trades very fast execution for rather slow development, especially of larger code bases, if you want correctness. It's fine for tiny programs though.

(Ruby, of course, has its own set of jolly footguns, as any dynamically typed language.)

Then you should use assembly. I mean..is assembly really that bad?
no. assembly really is that bad.