4 ms·
People don't just use C because it is the most fun to program in but because it offers a unique set of trade offs that no other language (even most C-replacemen
by cardanome 5y ago
People don't just use C because it is the most fun to program in but because it offers a unique set of trade offs that no other language (even most C-replacements) hits.
It is based on a stable standard.
It is extremely portable and not in a target major platforms way - that is much better done in other languages - but in a being able to run on nearly every OS and hardware in existence. You can feasible port your C software to you weird hobby operating system.
It is simple enough that you could write your own compiler or at least something to bootstrap a proper one.
It is the Latin of programming languages. It is the common, cultural core we have. Nearly all bigger languages have some way to interact with C. If you want to write a library that can be easily used from any language, C is the way to go.
It is (relatively) fast too compile and creates binaries of minimal size that run at maximal performance. (Yes, you do make trade-offs in some of these aspects when using Rust or C++. Those trade-offs are worth it in many cases but let's don't pretend they don't exist. C serves as a performance gold standard for a reason.)
Yes, it is also a horrible language is many ways and should not be used for most projecs but the advantages can make all the difference for certain use cases. For projects like SQLite or Lua it was for sure the right choice to use C.
- ncmncm 4y agoSQLite and Lua could have been coded in C++ with no downside. They could be coded in Rust with some loss of portability, but nowadays anywhere you can compile C, you can compile C++. There is no difficulty whatsoever in exposing a C API from a library coded in C++.
- cardanome 4y agoThe point is not whether they could, they absolutely could but whether C++ or Rust would have been a better fit considering the values that these projects have. Just because you don't care about the downsides does not mean there are no there. First of all, which subset of C++ should be used? It is a huge language that only very few people can claim to master. So lot's of people wouldn't be able to understand or change the code anymore. That is quite the significant downside. Not to mention all the other downsides mentioned in my other post, like being slower to compile, bigger binary and so on. Yes, those downsides might not matter to you and should not matter for many projects but they do exists. C programmer often care more about building the best possible software not so much about having the best possible development experience while building. That said, Rust has much better safety guarantees, so it DOES offer some significant upside that C can't.For more complex software it is is definitely a very good choice.
- ncmncm 4y agoNow you appear to be parroting things you read somewhere. The statements bear only a tenuous connection to reality.
- cardanome 4y agoWhat exactly do you take offense with? I do have experience using both C and Rust. Arguably, my C++ is very limited but things like C++ being a relatively large language are well established facts and quite uncontroversial.
- ncmncm 4y agoThere is no disagreement on what "subset of C++" is best: anywhere you have a choice, use the newest method supported on your compiler, because nothing is added to the language without compelling reasons. It is true that some people resist using anything introduced since they first learned, with a few mired in C. But there is never any need to "agree" on that. "Bigger binary" is scurrilous propaganda. Compilers nowadays use the same code generator for C and C++: say the same thing, get the same code. Furthermore, optimizers have to guess less at you are trying to do, in C++, so can do a better job. C++ code for the same task is often smaller. "C programmers often care more about building the best possible software": this is just crude slander. Finally: "Rust has much better safety guarantees": C++ offers much the same guarantees, where you choose to exercise them.