+
AMDG
Goodman Coat of Arms

Goodman's Oak

Miscellaneous Thoughts, Projects, and Ruminations on Life, the Universe, and Everything

Why I Write C

Donald P. Goodman III 2 Apr 1207 (2 Apr 2023)

As anyone who has ever looked at my code will immediately know, I am an amateur programmer. That is, I program not because I'm paid for it, and not because I'm actually good at it, but because I love it. “Amateur” is French for “lover”.

So why C? There are so many other languages out there, many of which present much lower barriers to entry. Python is well-known, and supposedly quite easy; Lua is great, simple, and tiny; Perl, while reputedly “write-only”, gets the job done, and doesn't require mucking around in memory management; Java/Kotlin can be used to write native Android (or Android-derivative, like my own phone operating system, LineageOS); so why in the world would I ever choose to write C?

Well, let me tell you. But I'm not going to be going on and on about the lightning-fast binaries we get from manually-memory-managed compiled C code, or any other technical issues. I'm an amateur, not a computer scientist, remember? I'm going to give you an amateur's reasons. I use C because:

C is Hard

C is hard. C requires using pointers for anything significant; C requires lots of string-bashing instead of easy, convenient little string libraries; C requires manual memory management, for crying out loud! Not to mention undefined behavior; overflow of data types; the necessity of checking everything for return codes and the absence of almost any centralized error checking; and countless other issues that users of more “modern” languages never think about.

But I am programming not (just) to “get things done”; I am programming for the love of it. I am programming because, by programming, I get to make my computer do exactly what I want it to do, no more and no less. By programming, ideas that I alone have had, needs that I alone have incurred, desires that no other human being has ever had can be made real. In other words, programming is a joy for me, not a chore.

Because of that, I can choose the language that not only best serves my needs (as C usually does), but also the one that most challenges and delights me. And that language is C.

C is Low-Level

C, of course, is one of the original high-level languages, in that it provides some abstraction on top of the assembly code that formerly had to be used for everything; but compared to most other languages now, it is indeed very low-level, and that's what makes me love it.

C brings me right down to the bare metal of my machine. I am literally bouncing around memory, stringing bits of memory together, jumping from one place in memory to another. There is some significant abstraction from assembler, but the mapping of C to assembler (assuming no optimization) is very simple and easy to model. I am right there at the very bottom of my technology stack; sometimes I'm even manipulating raw bits, if I want to be. I program because I love it; and nothing gives me the purest of programming, the closest relationship with the mysterious machine under my fingertips, the way that C does.

So why not just learn assembler? Well, because it's not portable. C provides just enough abstraction that it is easily ported to any machine I want, but still so little that I'm very close to the metal. And my little amateur heart can't help but love it.

C is Ubiquitous

C is everywhere. Really, everywhere. I recently had an old computer scientist mention to me that C was going the way of Fortran, and I couldn't help but laugh. There are four major groups of operating systems for computers in the world right now, and all four of them are written predominantly in C. There are two major mobile operating systems; I can't speak for iOS, but Android is just Linux under the hood, and even though its API is Java/Kotlin, it, too, is written in C. And all the languages that are supposedly taking the place of C: what are they written in? Java is written in C; Python is written in C; Perl is written in C; Lua is written in C. C isn't going anywhere; or rather, C is going everywhere, exactly where it has always been.

C is ubiquitous precisely because of the other traits I've identified. It's so low-level that it's difficult to use in many ways; it provides an abstraction layer over assembler, but only just, and it's very small and compact as a result. But it's high-level enough that it is easily ported to pretty much anything, making it ideal for everything from tiny embedded systems to gigantic mainframes.

No matter what I write in C, I can be confident that it can be ported to any hardware in the world that I would care to run it on. This ubiquity is one of its greatest strengths for me.

Conclusion

So I write in C. It's difficult, but it's a delight. I wish I knew C better; I wish I could master the handy idioms for data structures, and the code surrounding them, that the real masters use. I write, at best, functional C code; it's not beautiful, it's not rigorous, and it's not clean, but it does the job.

And, of course, it's a joy—and that's the material point.