Looking back, if we had C3 back in the early days of C, a lot of things might have been different.
C was designed to be simple, flexible, and close to the machine. It gave programmers power, but with that power came pitfalls, buffer overflows, manual memory management, cryptic macros, and debugging headaches. At the time, those were just the trade-offs of writing fast and portable code.
C3 keeps everything that made C great but smooths out the rough edges. It eliminates the need for header files with a modern module system, making code organization cleaner. Macros in C were always a bit dangerous, C3’s semantic macros would have saved me a lot of headaches. And then there’s gradual contracts, if I could have had a way to enforce constraints at runtime and compile-time, debugging would have been far less painful.
Error handling was another challenge in C. You had to choose between clunky return codes or using setjmp/longjmp
, neither of which was ideal. C3’s zero-overhead errors combine the best of Result
types and exceptions, making error management both efficient and natural.
Then there are slices, a built-in type-safe "pointer + length" abstraction. We always relied on raw pointers in C, and tracking lengths was error-prone. This feature alone would have prevented countless bugs in early UNIX development.
Generics? We didn’t have them in C, and C++ made them complicated. C3’s generic modules keep things simple, just as they should be. Reflection at both compile-time and runtime would have made metaprogramming vastly more powerful without resorting to preprocessor tricks.
And debugging, ah, debugging. I still remember chasing down segmentation faults with print statements and core dumps. C3’s detailed stack traces and built-in safety checks in debug mode would have made life much easier.
But what I love most? C3 isn’t trying to replace C, it just makes it better.
If we had it back then, we wouldn’t have changed the direction of UNIX or C itself. But we sure as hell would have written a lot fewer #ifdef
s, spent less time tracking down memory bugs, and had a few more hours to enjoy a good cup of coffee.
C3 is what C might have been, given a few more decades of hindsight.