by EdSchouten · 4y ago · 0 comments
C is sort of a dead end. There is very little innovation there. And that's fine; the users of the language seem to want it that way. They just want to write software the same way they've been doing for the last 20 years. Why would such a conservative user base want to switch to a different language like C3?
Linus once said this about Subversion: "Subversion has been the most pointless project ever started... Subversion used to say, 'CVS done right.' With that slogan there is nowhere you can go. There is no way to do CVS right." Could C3 be the Subversion of programming languages?
C is a small language. There are benefits to that. But it also has a handful of historical oddities. Innovation here means to keep C small while also getting rid of those quirks.
C++ is enormous. Rust is headed in the direction of similar enormity.
Zig is an interesting “exception” due to its strong compile-time metaprogramming capabilites, resulting in a small, but quite expressive language. But all 3 has a future. C is here to stay, but I really wouldn’t start any new project in it.
I don't think this is a fair characterization of rust really. For the most part the things on the horizon still for rust seek to reduce complexity by filing down sharp edges that force you to write complicated code. Stuff like GATs seem complicated until you repeatedly slam your head into the lack of them trying to do things that "seem" natural.
C++ on the other hand (after 2011) just never saw an idiom it didn't like enough to throw on the pile and there's little coherence to the way the language has grown in the last decade.
IMHO it's been incoherent from the earliest times.
The lame exceptions without 'finally', and no consistency in exception types. Then the desperate attempts to make all resources into objects, except that practically no OS calls bothered with this.
The overloading of the shift operators in the standard library. Indeed, operator overloading itself is just a recipe for abuse. You read 'a=b+c' and you literally have no clue what that means.
Multiple inheritance with the brittle semantics.
The awful STL, with its multi-kB error messages (the allocator of the trait of the string of the tree of map of king Caractacus doesn't match ...)
There's no wonder the 'obfuscated C competition' never happened with C++ given the fact it's unreadable, right out of the box.
I never understood that argument. Even in C operators do different things depending on what types you pass it. Two very simple examples:
1. Adding a number to a char* vs adding a number to an int* (or a pointer to any other larger type). The second automatically creates an invisible multiplication. This was confusing for me when I first learned C after already knowing the concept of a memory address (which is just a number). It was an unexpected abstraction for me.
2. This regularly bites novices to programming: Dividing two numbers. If at least one of them is floating point, you get the 'correct' result, overwise rounded towards zero. To 'fix' it, you have to explicitly cast at least one of them to float or double. Then the language imlpicitly casts the other for you. std::pow went the other way, which is less confusing. It always promotes integers to floating point numbers and returns a floating point result.
As soon as your language has types and operators, you get operators that do different things based on the types of the values they are applied to. The only new thing that operator overloading adds is that it makes libraries first class citizens.
https://www.amazon.com/C-Good-Parts-Gregory-Satir/dp/1449319...
There's a significant number of C programmers who want something slightly more modern and convenient but don't want to write C++ due to a number of reasons.
I think Zig, D are examples of this niche but syntax wise they don't completely look like C.
This is technically true, but someone that likes writing C while wanting a few extra features would mostly be able to write the same C code they always have if they stick to D's betterC. (I'm not familiar enough with Zig to comment on that.)
Edit: Should also add that D now compiles C code, so a C programmer could continue to write C as they want, write a few D functions where those features help, and compile them without writing any binding code.
That is because C's type declaration format is provably, as in actually provably, terrible.
There is a reason the majority of modern languages have switched away from how C declares types.
Honestly it'd be nice if the C committee could find a way to tack on a new variable declaration syntax to C, so everyone didn't have to keep looking up, or using tools, to declare non-trivial function pointers.
The C committee should do basically nothing. If someone, somewhere, finds an actual bug in the spec, then fine -- fix that. But don't go adding new features.
If you want something new, then make a new language.
Leave C alone.
Adding an optional new declaration syntax isn't a new feature, it is a change to the parser.
C's declaration syntax is awful. In fact I'd go so far as to claim that one reason function pointers aren't heavily used in C as compared to modern C++, C#, JavaScript, etc, is purely because the syntax around them is so awful.
(They obviously are used, but no one likes using them)
Purists can always use std=-c89.
And it’s not a dead end at all - embedded systems, wasm, wasi, really fast things, and aside from assembly it’s one of the first things on newer platforms (risc v for example).
I like Go for the same “try to keep it minimal” reasons, and keen to try Zig when I have some time.
I think the bias you are implying might be misplaced.
Want multiple heaps? That'll be a compiler extension. Want to specify exactly where a variable is laid out in memory? Compile extension.
Have a memory layout that isn't just a flat map of address space? Better reach for a compiler extension.
Hardware registers? Eh, overlay it with a union or a struct or something, it'll be fine. Unless you want some sort of non-trivial typing on those registers.
People forget that C is written against an abstract C machine. C is not written against the underlying hardware platform. And the abstract C machine may differ from your target hardware by a fair bit.
I would argue that the time you need to invest to get something done correctly in C is a cost you can avoid with (modern) C++
If I wanted / needed something more oo I’d probably learn rust.
C++ is everywhere doing amazing things so hate - unreal engine! - just really not my cup of tea.
I mean, of course, I also like short compile times... but since when are they considered a serious cost? What are we talking about? Seconds? Minutes? Hours?
Are you using your compiler as a syntax checker? Always compiling everything all the time?
Especially since you compile once, what you run a million times and now that everyone is running around with what would have been considered a supercomputer decades ago in their backpack, and a half in their pocket.
Of course I think stuff should compile fast (that's why we use Make, CMake, ninja, etc.) but I would never chose C over C++ because of compile times... Code that requires high mental load and solving the same stupid things again, and again, and again... still costs more time than my compiler can get me back IMO.
C is like a table saw without a blade guard. Simple yet precise, powerful, flexible, and will cut your fingers off if you aren’t careful.
But it’s often exactly the kind of dangerous saw we need sometimes.
There’s no point in trying to improve it - there are plenty of other, safer saws for that.
C is awful, C is terrible, C is almost always the wrong answer.
But when it hits the spot, it's a fantastic wrong answer for a bunch of things.
Actually I just want to write software the same way I've been doing it for the last 40 years, but otherwise yeah.