C is okay except safety. Look at the CVE lists and they are still full of memory errors and it’s 2024.
The problem isn’t that good programmers can’t write good C code, though anyone can make a mistake. The problem is what happens as code ages, is worked on by other people, gets PRs merged, and so on. Bugs creep in and in an unsafe language nothing catches them.
C also makes string processing hellish, but that could be fixed with libraries and isn’t necessarily the fault of the language.
C is enjoyable to write with although if others rely on your code, safety should have a higher priority.
The one thing I could never enjoy in C after getting used to languages like php and python is string handling. It isn't just dangerous but very tedious, complex and lacking elegance. Lack of a native string type and string operators really sucks.
I like being able to do "hello "+"world".
Another pro the author didn't mention is how my crapy code from 10yrs ago still works today. Can't say that about rust, go, python or most modern languages. It really sucks how "planned obsolecence" has crept it's way into programming languages.
It's not bad because it's old, it's bad because of how unsafe it is. There are older languages than C that are safer, but they didn't gain the popularity C did.
I do not think C (or any other programming language) is the best programming language. However, I think that the memory safety often gets in the way, and that even if it is helpful (which it often is), memory safety is not the only important or helpful feature anyways.
Let‘s just agree that C is not a good programming language according to modern standards: basic integer types are a complete mess with varying sizes and confusing implicit casts. The advantages of null terminated strings do not matter anymore, but the disadvantages matter more and more. The compilation model with headers is a mess compared to module systems. The C Preprocessor is an abomination. The complexity of the language is surprising.
Well, C is pretty bad, compared to modern languages. It's full of buffer overflows, undefined behaviour, etc. Just because something is popular doesn't mean it is well designed.
I would disagree that C is going to be a 100 year programming language. I think the recent focus on safety is going to not only turn businesses away from using C but that they will active push C out of their code bases in the quest for safety. C was fine back before networking was everywhere. Today, it's a disaster waiting to happen in every C program. Sure, there are C programmers who claim they can write safe C code, but the numerous hacks prove they can't. Why wouldn't a programmer prefer a language that handles most of the safety for you, and is designed to allow for better optimization to boot?
For me, this argument in favour of C is really missing the point. In the long run, maintenance costs dominate, and unsafe languages like C lead to programs that take more and more programmer time to maintain, and it becomes harder and harder to see the high-level structure and optimize that through refactoring, rather than the low-level bottlenecks that show up in profilers.
Of course, for now. But I still disagree that it is as easy (or hard) to write C without bugs as in any other languages. Most people should not write C.
The good thing about C is there is an amazing tool support that can make it as safe as any other language. The bad thing about C is that most developers don’t know about (or don’t use) all the tools.
Too bad we have all that legacy C code that won't just reappear by itself on a safer language.
That means there are a lot of not careful enough developers (AKA, human ones) that will write a lot of C just because they need some change here or there.
C can be coded much safer as long as I don't code in 'odd' ways, e.g. trying to be really smart with it. By following common-sense coding rules it seems pretty safe to me.
Like it or not, C might still be the most widely used language after 50 years, it will not go away, instead, future AI code review tools, static analyzers, more powerful compilers will evolve fast to make C safe and alive. Why, the price to replace it will be much higher in practice, it might simply be impossible.
C is a garbage language. It has a lot of undefined behaviour. It isn't safe. It isn't even strongly typed. It's only marginally better than a macro assembler. C programmers consider that a virtue but programmers who want to write safe, robust code, know C is garbage.
My complaint against C is that some of the smartest people on the planet use it to write infrastructure that regularly fails catastrophically. If the experts who love it aren't capable of writing correct code, I have no chance whatsoever. Humans just aren't good at the fiddly bits (remembering to free(); not to free() twice; not to use after free(); accidentally adding a second clause to a non-bracketed if expression; how many times to we see these in vulnerability reports?).
C is obviously very powerful. There's no denying that. But it does approximately zero of the things to help programmers that a modern language does. It's not even strongly typed in the usual sense (is there the equivalent of casting void pointers anywhere else?).
Finally, C is slow. Yeah, you read that right. Its main problem is that it has no non-wizardry high level semantics for parallelism. For example, modern languages have map() to say "do this operation on all of these items". In C, you have to write that as "for each item in this collection, do this thing, then the next, then the next, ...". If the compiler is exceptionally smart, it might infer what's going on and help out. But with map(), you're explicitly telling the language "I want all of these things to be done" and it doesn't have to infer anything.
I respect C. It's given us a lot of great stuff. But there's no way I'd willingly start a new project in C today given the alternatives. I am dumb, and given the choice between languages which help me and languages which are basically a small step up from assembler, I'm going with one that gives me a reasonable shot at writing safe, fast, and understandable code.
Let's try this again. As a language C is not that horrible and it doesn't have to be as sloppy and as insecure as it is in popular compilers. In fact, I believe 99% of the C code is not performance critical and can benefit from simple runtime checks to ensure memory safety. Not that much needed to "save us from C". But ultimately no one cares, inventing and playing with new languages is way more fun.
I agree with what you're saying about the problems that C has (or rather the problems people have with writing safe and secure C code), but I do think the language matters; just from the perspective of having any hopes of being adopted.
C is largely immune from all the language wars, because it's everyone's reference point. I think it will be very difficult to get enough people to sign off on another language for systems development. Everyone thinks they know what everyone else should use; and it makes for a very fractious environment with regards to what languages should get used... C# and Objective-C are good examples of that.
I don't see a future where C survives, not only because of memory corruption bugs (although that's a pretty big one), but also for usability: the lack of package manager, common build system, good documentation, good standard library, etc. are just too much to compete with any modern system language.
The problem isn’t that good programmers can’t write good C code, though anyone can make a mistake. The problem is what happens as code ages, is worked on by other people, gets PRs merged, and so on. Bugs creep in and in an unsafe language nothing catches them.
C also makes string processing hellish, but that could be fixed with libraries and isn’t necessarily the fault of the language.
reply