r/ProgrammingLanguages • u/P-39_Airacobra • Jul 27 '26
Discussion A hole in systems programming language design
Given the recent discourse about systems programming I wanted to throw my 2 cents in. This may be a controversial take in a subreddit that's all about innovation and improvement, but I think a lot of budding systems languages are trying too hard to "fix C" and this is exactly why C has not been replaced yet.
Like it or not, C is successful. It does what it means to do very well. Yes, it bites you constantly, but developers have made some form of peace with this because they appreciate the essence of the language. Systems programming is a very pragmatic field, and what works, works.
A lot of language designers want to improve on C, when by nature to "improve on" C is to depart from it, because C is less about what it includes and more about what it omits and what it lets you do that other languages don't.
If you want to replace C, you need to just make C but without the pain points. Less undefined behavior, more standard compiler behavior, easier function pointer syntax, safer macro system, etc. The things that C can't do because of backwards compat.
On the other hand, bolting on features, revamping C's core nature, aren't going to give you a language that will replace C at the low-level or among hobbyist programmers. Most developers aren't as concerned about what C lets them accomplish, as they are concerned about all the painful tedious tendencies of the language.
7
u/WittyStick Jul 27 '26 edited Jul 27 '26
Yes, the hole in systems language design is a language which, from the PoV of any other language, is indistinguishable from C.
Your entire desktop/server/mobile stack is built on C, all compiled with compilers which emit exactly the same ABI. Every program has many dependencies, which transitively have more dependencies, all predominantly implemented in C. Half a century of software underlying everything your language needs to be useful and not a glorified over-engineered calculator.
Mistake #1 is many of these new languages implement their own ABIs/calling conventions. They use an "FFI" to make their language useful - it gives them the ability to call libraries that were (predominantly) written in C.
However, this FFI is a one-way ticket. You can call C from your language, but nobody else can call your functions from theirs. A library written in your language is a little island, usable exclusively to users of your language. A Python function can't trivially call an Odin function for example, because it doesn't speak the Odin calling convention. It doesn't know what this implicit "context" thing is. It can call a C function. Every (relevant) language knows what a C function is, because they had to implement an FFI to make their language useful.
"I built a website using RustScript, which no browser supports, because I dislike Javascript. Why is nobody visiting?"
"English sucks so I wrote my latest paper in Esperanto. Why is nobody reading it?"
"I compile my functions to this bespoke ABI. Why is my language not replacing C yet?"
Functions written in this "FooLang" should be callable with the existing FFI machinery of any other language - not with magic extensions or wrapper libraries.
Let's assume we don't make this mistake - we take the sensible approach of using the platform C ABI unchanged as our "FooLang" ABI, and anyone can call our functions trivially. However, our API - the definitions of our types and functions is written in "FooLang". For some strange reason, the Rust compiler cannot parse our "FooLang" definition files. What gives?
Mistake #2 - FFI wrappers. You have hundreds or thousands of usable libraries on your machine (mostly written in C), but to call any one of them you have to translate the definitions to your calling language's syntax first? What a dreadful use of time.
The solution here is, since most of those libraries were written in C, and have definitions in C headers - we should just parse those C headers and programmatically create the bindings - preferably transparently so we don't need to have several tools run at different stages. Our compiler should just understand C as par for the course.
Of course, this isn't trivial because a header file isn't just code to be read - it must also be preprocessed. So we need a C preprocessor too. We also need to handle inlining and internal/external linkage - so we essentially need our compiler to understand not only the C ABI, but the C language.
But also, since every language can call C libraries, speaks the C ABI, and should be able to read C headers (perhaps with separate tooling at separate stages to translate the bindings) to emit calls to C functions - any libraries we write in our own language should also be callable from other languages right?
So for our own types and functions written in "FooLang", we should emit a C header with compatible definitions so that we could call it from C (and by extension, any other language).
So for a "C replacement," we would first need "C parity," which IMO, the above is a bare minimum requirement - complete platform ABI compatibility, and ability to parse, understand, and emit C headers so that our language is not just a little island of its own, but is actually callable from other languages like C is, because the work has already been done for them to interoperate with C.
This isn't to say there's no use for other languages, but for a "C replacement," one must understand why we use C in the first place. Embedded uses aside, one of the primary reasons we'd write in C is precisely to implement libraries that can be called by others - and not exclusively "FooLang" users.
If I'm going to write a useful library, I want it to be useful for everyone and not just the dozen or so Odin programmers that exist.
7
u/stianhoiland Jul 27 '26
The curse of Good Enough.
62
u/stylewarning Jul 27 '26
I think you attribute C's success to the language itself.
The way to replace C is in part building a new language, but more importantly, writing critical code in that language. C will stay for as long as core infrastructure (like the Linux kernel) stay written in it, regardless of how amazing a new language may be.
36
u/mister_drgn Jul 27 '26
Multiple languages are striving to be C without the pain points (e.g., C3). That said, adding new features that improve quality of life is obviously going to be part of any C replacement, so I'm not sure what you're getting at.
50
u/awoocent Jul 27 '26
Struggling to imagine how you look at the ecosystem of new systems languages - Zig, Odin, Hare, C3, Jai, V, etc - and somehow come to the conclusion that the status quo is anything else!
20
u/Smallpaul Jul 27 '26
C’s core, Wild West, loosely typed nature IS what’s wrong with it as a base for highly reliable systems.
The pain of discarding backwards compatibility is very high. People will only do it for some major upgrade in capability. Making a hobbyist language with only a few minor improvements but also requiring a code rewrite is doomed to failure.
The market has said very loudly that the main feature they want is safety, which means a pretty major overhaul.
5
u/umlcat Jul 27 '26 edited Jul 27 '26
Interesting post. I also in the "made my own programming language to fix C or C++" trend.
Yes, I notest that there are several attempts of programming languages, such as Digital Mars D, Google Carbon, C2, C3, Rust, Apple Objective C, Apple Swift, CPP2 with its functional syntax proposal, and others.
Altought not considered "Systems Programming Languages", I do consider Java and C# with their Virtual Machines to be considered in term of syntax and features.
Just look how clean in design look C# compared to C++ .
I also have my own hobbyist ideas, but been delayed due school, work, health issues, hard drive and floppy drives backup damaged, COVID, and ADHD. I also been stuck with some custom compiler parser issue, because I'm doing a non custom parser in purpouse.
The original ideas started since 1995, at college.
As you already mentioned, I also detected that some of those features ideas from those programming languages, are useful. But at the same time, some depart too much from C or C++, that made developers avoid them instead of embrace them.
I'm working on my own personal project so developers and companies can be interested. And not to fall in the same problem.
Beside, some people have the "if its working do not move to another programming language" mindset.
As an example, I would preffered Digital Mars D, that has several extensions including classes, to split in a procedural version like "Plain C", and another Object Oriented version like C++ .
I like and respect the issues that the Rust developers is trying to achieve, but I do not like the Rust syntax. Before Rust appeared, I had a similar idea but with a completly different syntax.I still working in the concept.
I do not like much the "Lambda syntax" or "functional Syntax" proposals like Cpp2 or Python for "Systems Programming". I think "brackets and semicolons" are better for "Systems Programming".
Several features that were previously implemented thru the Plain C and C++ preprocessor are slowly converted to part of the syntax as features like constant declaration or module import. Boolean types and boolean operations are now part of both Plain C and C++, as Pascal did originally, instead of macros.
Just my two cryptocurrency cents contribution ...
8
u/FlamingBudder Jul 27 '26
I think people need to actually learn type theory and the theoretical study of programming languages.
Most people who post here just straight up don't know anything about programming languages more than the mainstream PLs that they are exposed to. Even then they only have an intuitive idea of how each of the features work. Thereby there is an obsession with systems programming because that's what's cool when all you know are mainstream PLs
Compare that to the actual PL literature which has many novel and interesting things like dependent types for program verification, program synthesis, effect handlers, resource aware types, concurrency and distribution through substructural and modal logic, etc.
Many of the projects posted talk about random things like concrete syntax (which is much less important than the semantics of the language), and random "what if we made a language that does X) and the X is just some naive idea that demonstrates you did not study PL theory at all
If you want to get into PLS, making your own compiler for some language while you don't know much about the field is not as productive as first reading introductory text like Pierce's TAPL or Harper's PFPL
4
u/EggplantExtra4946 Jul 28 '26 edited Jul 28 '26
Yours is not a new take but let's call it the "weak C replacement theory":
New softwares that used to be programmed in C are going to predominantly use a weakly improved C-like language.
The "strong C replacement theory" is much more likely:
New softwares that used to be programmed in C are going to predominantly use a "low level" language that is an order of magnitude better than C. ("low-level", meaning statically typed natively compiled)
C's minimalism doesn't provide anything in itself, the essential things that C provides is speed, no overhead and good memory control and those don't require a minimalist language.
What low level languages and most languages sorely need is the triptych: metaprogramming features (macros, compile time execution, conditional compilation, instrumentation, introspection, etc..), abstraction/composition features (modules, classes, abstract classes, parametric polymorphism, function overloading, etc..) and better type checking/semantick checking. The first two don't impose any restriction on runtime speed and memory access, quite the opposite.
For the type system it depends but even a type sysytem full of explicit escape hatches would be safer that what C has and I believe that a well design advanced and safe type system would rarely need arbitrary unsafe pointers, in the sense that most exotic memory objects I can think of can be given a type, a memory layout and a lifetime information that can be integrated into the type system. Even a process's own function call stack could have all that for example, no need of unsafe pointers to walk over the call stack. Even pointer arithmetic can be made safe, look at ATS, as long as memory objects pointed to have a well defined type.
4
u/koflerdavid Jul 30 '26
You make the classic mistake of attributing the difficulty of changing the status quo to its quality. Instead you should consider that the status quo is hard to alter because there is simply massive momentum behind it.
C is not going to go away anytime soon for better or worse because of the massive amount of code that already exist. That code might be latent source of bugs, but apart from that it makes up very mature, battle-tested systems, and replacing something like that is not easy, as the brave folks at Ubuntu found out when they decided to replace sudo and coreutils with Rust rewrites.
1
u/JeffB1517 Jul 27 '26
Obviously, C is institutional. C++ and such minor refinements exist. There used to be a more diverse ecosystem but the industry standardized on C as far as both compilers and chips. What a replacement language needs to do is compile down close to or better than your typical programmer's C against a toolchain optimized against C. Which is a big ask.
But at this point, at least in open source, we aren't compiling directly but rather using LLVM. LLVM is fairly language independent while itself being written in C++. I.e., compiling to LLVM with a heavily optimized compiler captures most advantages of C. The better language often allows for better optimization; programs can cross the bar. Consequently, we have two viable candidates which are making progress: Zig and Rust.
So I disagree with your thesis.
4
u/ZippiDxD Jul 27 '26
Literally odin is filling this whole already. Its C but more fun to use
2
u/WazzaM0 Aug 01 '26
You made valid points but didn't really specify a hole but a rather a design smell about new languages.
I've long thought that C++ tried to be an extended C but failed to have a strong vision about what was missing, do it added complexity and more traps.
You're right that C does one thing and does it well. It has sharp edges and, like any tool, will take off your toes if you fail to treat it with respect and learn to use it, thoroughly.
2
u/Limp-Temperature1783 Aug 01 '26
Considering that C used in systems programming tend to differ significantly from the usual POSIX C, I'm not sure what is there to fix. POSIX sucks. It is old and decrepit. And C compilers suck, using them is like using chainsaw to cut some butter. There are small C compilers, but they lack optimizations. As for UB, it's more of a design problem, not a language one. Function pointers are convoluted, I agree here, not sure how many are even using them for the task.
Overall, I think if C could have nice things like slices and better error handling with a compiler that tells you something useful, you'd beat C. But these are QoL changes that won't push C from its niche. There is a lot of hate for C preprocessor and I think it's both valid and undeserved, because it's not that hard or painful to use, to be honest. I'm not programming in C not I am a systems programmer, but every time I think of doing something in C it's kind of refreshing for how little I need to accomplish a lot. It's predictable and nice to use, if you pay attention to what you're doing.
Memory management is also rather ubiquitous, I'm not sure how people find it hard. It's not like we even have to align memory by hand these days, unless you want to write something with maximum efficiency. I'm writing this because people keep inventing languages and selling memory safety as a gospel, but it's kind of easy to achieve. I also don't get the hate about goto. It's unstructured only if you overuse it. Having a way to jump somewhere without a ceremony is a good thing, most structured code is just sugar over jumps to reason for you, which is fair for most common things.
3
u/Rechenplaner Jul 27 '26 edited Jul 27 '26
C is standardized, an ISO language. Industry can rely on that. That alone is reason enough why no hobbyist created language will ever replace C, not even languages backed by a corporation. Especially in the embedded sector, C remains the top dog and could not really be displaced by C++: This will remain the case for a very long time.
Writing system software like kernels in other languages has not proven successful so far because C was simply designed for that purpose, whereas other languages offer too much fluff that is difficult for system programmers to digest. Rust would have good chances to take that place because of its hype, but its complexity will always inhibit it. Therefore, I do not believe that Rust will ever dominate here.
C is designed as a very simple, sloppy half-assembly language and thus struck a true chord: It can simply be taught at universities more easily than Rust, for example. At my university, C was the language used in the first semester to teach programming. I hated it back then, but I am sure C++ or Rust would have been even worse because they introduce much more abstraction that is way more complicated than just understanding pointers.
I think C will never be replaced by other system programming languages, but rather made redundant by newer hardware where one can write system software even with garbage collected languages because, for example, graphene chips or purely optical data processing will then offer fifty to one hundred times more performance, where the struggle with manual memory management is really no longer worth it, similar to how today nobody writes kernels or games in assembly for performance reasons.
1
u/david-1-1 Aug 02 '26
Compare with Swift or Rust: larger learning hurdles, but bugs are more likely to be found at compile time. The ultimate general purpose language has not yet been designed.
1
u/JeffD000 Squint Aug 22 '26 edited Aug 22 '26
The real value of C is that it is so small, it can more often than not be ported to even an exotic new hardware platform in less than a month. Sometimes, for "simple" architectures that look similar to the architecture you are porting your existing compiler from, it can be ported in as little as one day for the core compiler and for all the libraries that don't need to access system specific registers or memory mapped I/O.
1
u/flatfinger Jul 27 '26
A good systems programming language should acknowledge that the role of a translator is to convert source code into a specified sequence of imperatives for the execution environment. In some cases, a translator may be allowed to select freely from several possible ways of processing a construct, and the range of allowable choices may be based upon expectations about how the execution environment will process certain actions, but the action should be defined in terms of the range of possible choices.
For example, given:
a dialect suitable for systems programming, may allow a compiler to consolidate the load of
x2with some other load that happened before the load ofx1, but be agnostic as to when or whether the value ofx2might be changed by something outside the control of the current execution context.Very few parts of the language proper need the notion of "anything can happen" UB. While many actions might cause an execution environment to behave in an entirely unpredictable fashion, the language itself shouldn't care about what the knowledge programmer does or does not have about the way the execution environment will respond to any particular stimulus.
1
u/phovos Jul 27 '26 edited Jul 27 '26
I agree op but technically I think the timeline is such that it NOT being backwards compat (the older computers had this symmetric arithmetic pl) ended-up hurting it, as a circumstance of timing and the market, etc. The PDP-11 being a 'platform' that is 'desirable' and then imprinting itself where it did not belong. Prepare yourself I got a rant cannon, shiver me timbers!
Aide/docs: (first edition)"The C Programming Language":
https://i.imgur.com/UqGJDoU.jpeg
p91) 'pointers are variables so they can be manipulated as other variables can'
comment: declaring an array is a contiguous block of addressed mem because its name represents the address of the first element.. but it is not a pointer it is a type array; but Bryan is correct because of the fact that:
> names decay when used as a pointer to its first element
> only when used in an expression is an array a pointer to its first element, otherwise it is literally an address
And that sort of adds-up when you consider the isomorphism check that is the call by name call by value homo-diffeomorphism. Way too many syllables to say it is perfectly balanced, like a binary bijection itself (the complicating factor is that this is unitary with respect to time operators but I digress).
P91cont) he goes on to describe a swap(a, b) isomorphism check, which "Because of call by value, swap can't affect the arguments a and b in the routine that called it... Fortunately... The calling program passes POINTERS to the values (a, b), to be changed":
```c
swap(x, y) /* WRONG */
int x, y;
{int temp;
temp = x;
x = y;
y=temp;
}
```
Leading to the legendary syntax: `swap(&a, &b);` where "the '&' operator gives the address of a variable, `&a` is a pointer to a. In swap itself, the arguments are declared to be pointers, and the actual operands are accessed through them.
p92) "One common use of pointer arguments is in functions that must return more than a single value"
This right here is why C is fast, it is the best 'replicator' known to man, a many to many correspondence functor.
pg93) "Any operation which can be achieved by array subscripting can also be done with pointer."
pg94pictured) "When an array name is passed to a function, what is passed is the location of the beginning of the array. Within the called function, this argument is a variable just like any other variable an so an array name argument is truly a pointer, that is, a variable containing an address."
"There is on difference between an array name and a pointer that must be kept in mind. A pointer is a variable but an array name is a constant"
pf98) "Second, we have already observed that a pointer and an integer may be added or subtracted. The construction `p + n` means the n-th object beyond the one p currently points to. This is true regardless of the kind of object p points to, which is determined by the declaration of p." ....
pg98contd) "For example on the PDO-11, the scale factors are 1 for char 2 for int and short and 4 for long and float and 8 for double".... "Pointer subtraction is also valid, if p and q point to members of the same array then p - q is the number of elements between p and q." ..."Other than adding or subtracting a pointer and an integer and/or subtracting or comparing two pointers, all other pointer arithmetic is illegal. It is not permitted to add two pointers or to multiply or divide or shift or mask them, or to add float or double to them.."
This is it, right here; we need to be able to be able to shift and mask them like the old heads used to do with raw assembly instructions; straying-away from this, because of the PDP-11's new features, is I think a 60 year mistake. C is this amazing language but it can't even do the most phenomenal thing; shift and mask many-to-many, serially.
pg95see-pictured-ps) handwriting (mine) "This is the fundamental operator of x86. Diffeomorphism creates many to many correspondence. The 'particle' of non-linear logical dynamics".
(ignore this one but including what it says in-case it makes someone mad they can't read it) "In much the same way as in the continuum; the 'digital' set theoretic universe has its core operators but one of them eludes me"
"The isomorphism between two different operators is literally the root of all software (x86/C-like at-least)".
edit: my edition I'm referencing is printed 1978 NJ. Not actually sure if that is 'first edition'.
1
u/initial-algebra Jul 27 '26
New software isn't being written in C, except maybe by hobbyists. For a language to be a successor to C, it has to be able to replace parts of a C program, without replacing the whole thing. That's not too hard, since any platform's C ABI is extremely predictable, but it does lead to a polyglot repo. And, if you have to pay that cost either way, why not use e.g. Rust instead of a brand new language that is not significantly different from C and has no ecosystem or support yet?