6 ms·
After All These Years, the World Is Still Powered by C Programming
- socmag 10y agoGood! It's really awesome
- vvanders 10y agoThe comparison to C++ with respect to exceptions is a bit misrepresented. In platforms where size/perf matters they are turned off at the compiler level(along with RTTI). This was always the first thing we did in gamedev right after turning on W4. Overall decent article though.
- cowardlydragon 10y agoSigh, I know this is trollbait... but why not. If you have any self-awareness of C as a programmer, you know that C is a simple, powerful, but poor language. Much like the English language, the popularity and endurance of C is due to historical, political, and inertial reasons. English most certainly is not a perfect language. But it is the dominant economic language of our time and will be even with billions of Chinese and Hindu/etc speakers. C might be technically portable with sufficient #defines, but I wouldn't call it inherently and magically portable... Now, because it has been used in most computing environments, there exists the knowledge and examples of coding conventions to enable cross-platform code. But the notion that C has portability features that are impossible to beat on a theoretical level is ignorance and fanboy culture. Java alone, while not perfectly portable, hints of true portability with simplicity and power. LLVM also hints of purer portability capabilities, and to a lesser extent, dotNET. “C is a great language for expressing common ideas in programming in a way that most people are comfortable with. Moreover, a lot of the principles used in C – for instance, argc and argv for command line parameters, as well as loop constructs and variable types – will show up in a lot of other languages you learn so you’ll be able to talk to people even if they don’t know C in a way that’s common to both of you.” This is pretty much horseshit from any "ideal language" judgement. Simply because of historical and practical reasons, C is generally known by any developer of ability. C has no special magical power of communicating ideas when viewed from fundamental linguistics. That C constructs and conventions appear in other languages isn't a supreme validation of C conventions... it's just political and linguistic convenience. I salute C for it's many fruits, it was the right language at the right time with just the right amount of freedom (and executive ignorance on the part of Bell Labs). It has earned its continued existence on those laurels. But should a superior, portable, auto-memory-managed language appear with cross-compatibility in runtimes, and even a C -> Language perfect translator... I wouldn't see why people wouldn't use that. C++ was a failure in this regard. Rust... we shall see.
- mjevans 10y agoI want to stay that for portability I'd recommend Go (golang), but my experience with it has shown that the standard library mostly covers parallelism, ///basic/// file I/O, and working with network data-structures. It seems to be a good language for writing 'glue' daemons; servers that co-ordinate the flow of information between different end points or otherwise control the overall state of a system. IF you need to do lower level things there are 'unsafe' methods for binding to the native libraries and interfaces of a given platform (but that impairs portability). I think that with some refinement to the standard libraries Go could more easily handle data-streams that could choke Python 3 (/forcing/ //valid// Unicode everywhere by default isn't ideal; be tolerant in what you accept and strict in what you produce). I like both Go and Python for higher level languages. They have strengths and weaknesses, but often one will be the correct tool for a given job. Both also benefit from external libraries, often written in C. I think that C will remain, any replacement probably won't have garbage collection or other such features. Those belong in higher level languages, which are fine things to use in many circumstances. C is common /because/ it's low level, it's similar to a stenographer's shorthand for assembly, but more like a recipe for what to do in general. I could see a stripped down version of Go, or maybe rust (I haven't tried this yet), or something else similar replacing C, but it would likely be a strict subset. Mostly what I think a 'C replacement' would bring is less undefined behavior and a stronger implicitly re-entrant code model; I also hope it does away with generic sizes and forces the programmer to specify (at least minimum size).
- samfisher83 10y agoDid you know JVM is written in c/c++. At some point you need pointers and maybe even assembly code. Use the right tool for the job. C is fine.
- catdog 10y ago1. C is heavily used in areas where it might not necessarily be the right tool for the job (for various reasons), the areas where you really need to fiddle around with low level stuff and safeguards turned off are comparatively small. 2. C might be fine for doing that but that does not mean there can't be anything better.
- recursive 10y agocowardlydragon, your comment is marked [dead], so most won't see it. That's unfortunate because it's pretty good.
- TheAdamAndChe 10y agoWhat causes a [dead] mark? Is it like a shadowban?
- zepolen 10y agoYes.
- deleted 10y ago[deleted]
- TwoBit 10y agoAnd C++ is used in so many places on top of that. Every web browser is written in C++. Most GUI systems are written in C++ (or Objective C). All gaming engines are written in C++, etc.
- humanrebar 10y agoIt's also my understanding that the LLVM, GNU, and Microsoft C compilers are technically (1) all written in C++. It's also my experience that larger embedded projects also tend to be C++. So maybe your microwave is written in C, but your car's control systems are probably C++, at least in the new parts. (1) So the gcc codebase is almost entirely C but it is compiled as C++. Someone else might be able to explain exactly what features of C++ made this an attractive option . My intuition tells me it has to do with better compiler diagnostics, perhaps involving type checking. I'm on mobile or I would research and provide more authoritative sources.
- shpx 10y agoTaylor's slides list the reasons to commit to writing GCC in C++: C++ is well-known and popular. It's nearly a superset of C90, which GCC was then written in. The C subset of C++ is as efficient as C. C++ "supports cleaner code in several significant cases." It never requires "uglier" code. C++ makes it harder to break interface boundaries, which leads to cleaner interfaces. https://lwn.net/Articles/542457/ https://lwn.net/Articles/542457/
- humanrebar 10y ago> It never requires "uglier" code. Again, I mostly agree with everything you wrote, but this is overstating things a little. Because exception safety can be a little more complicated than it first appears, you do end up having to do a bit more work in C++ in certain cases. One example of this is writing an external ABI in C++. Depending on how nice you want to be to the consumer of your ABI, you might need to add a try...catch(...) to every public function to make sure exceptions don't escape the C++ code. There are also tricky subtleties around writing, say, a swap function in the face of constructors that might throw.
- EvanAnderson 10y agoImmediately thought of this https://pastebin.com/UAQaWuWG https://pastebin.com/UAQaWuWG and the accompanying discussion https://news.ycombinator.com/item?id=12312623 https://news.ycombinator.com/item?id=12312623
- illuminati1911 10y agoIt would have been a nice article but there's just too much ridiculous hype in it. I'm not saying C is a shitty language or anything, but the reality is that the only reason why C is still around is the long history it has and the dominant position it used to have.
- shaklee3 10y agoNot really. With the exception of rust, you can't match the speed of C short of writing assembly. When you start a project you must decide what is important to you, and if speed is the number one issue, topically you use C. Many, many new projects start with C, mainly because so many of the fast libraries are written in C.
- goatlover 10y agoFortran, Ada, D? I guess D is out because of the garbage collector, and I've not heard of Fortran being used as a systems language, but it's certainly performant with C. However, OSes have been written in Lisp, and it has been used for embedded programming, so it's possible to make a language with more abstractions available similarly performant.
- catdog 10y ago> However, OSes have been written in Lisp, and it has been used for embedded programming, so it's possible to make a language with more abstractions available similarly performant. The right abstractions even increase the possibilities for optimization a lot, not hinder it. The fact that C is fast and often faster than others is simply due to its decades lasting popularity and the work which was put into compilers over the time.
- shaklee3 10y agoThose are fair points, but I was mostly focusing on languages that are still widely used. Fortan seems to be used the most of the three, and I rarely see it outside of niche scientific applications.
- 10y ago
- charles-salvia 10y agoStill, the thing is, I really don't buy into any arguments in favor of starting a new project, in C, today. The problem is that C suffers from some really serious disadvantages as a systems programming language, and it has no significant advantages over C++ or Rust, apart from subjective ideas like "it's simpler" or circumstantial issues like "my team doesn't know C++". Firstly, apart from a simple call stack, C has no automatic resource management. There are no automatic destructors. Thus it is too easy to forget to free some memory or unlock a mutex or decrement a ref count or whatever, especially when many code paths are possible after a resource has been allocated. The other options are to use the "goto cleanup" or "goto err" idiom, which is still way more error prone than automatic destructors. And secondly, despite being touted as so "efficient", C offers no way to write code that is both generic and free of runtime overhead, apart from preprocessor macros (which are filled with their own issues), or automatic code generation scripts. Both C++ and Rust have metaprogramming facilities which provide the ability to write generic code without sacrificing performance or maintainability. I mean, with C++, the automatic deterministic allocation/destruction alone is worth using it over C. And all of the downsides (larger binaries, etc.) can be overcome without much effort. I concede that the extra language complexity of C++ over C could be a disadvantage, but in my mind that doesn't outweigh the benefits.
- humanrebar 10y agoI mostly agree, but C compiles in terms of a binary interface, which makes it unique in it's ability to provide language agnostic libraries. You can do that in C++, but by wrapping your C++ in C, more or less. Rust might provide a compelling alternative here eventually, but it's still a young language.
- catdog 10y agoProviding no stable ABI and not being easy to bind to in general is really a major pain point of C++ for library/framework code. In contrast everyone and their dog is able to call into C in practice which is, I assume, a not to be underestimated reason why it is still so popular, even for code not leveraging its low level nature. Rust is really interesting here as they have chosen to make it more than an afterthought to provide compatibility. > I concede that the extra language complexity of C++ over C could be a disadvantage, but in my mind that doesn't outweigh the benefits. It's a problem, C++ is so insanely complex, full of magic which is hard to grasp and provides more ways to shoot yourself in the foot than to do it right (modern C++ seems better in some regards but still…). C is often chosen because people want sth. reasonable simple so I think a language fitting in between, being richer than C but still fairly comprehensible would be nice.
- j45 10y agoWith the arrival of WebAssembly this might see another boost.
- j45 10y agoAppreciate the downvotes, currently hiring c/c++ developers to build for the browser/WebAssembly!
- intrasight 10y agoIsn't a big part of its allure that it is "close to the metal"? When learning assembly language programming in the '80s, I would write a bit of C, and compile to assembly. It was very easy to mentally map from the one to the other.
- steveklabnik 10y agoThis is harder today due to optimizations, but if you also understand those, you can do it.
- intrasight 10y agoThat I get. I doubt this would work today. Even a simple program would generate reams of "boilerplate" and a reasonably complex program would probably leverage branch look-ahead and other optimizations.
- ben_jones 10y agoI've noticed a lot of open source projects that likely would've been written in C ~5 years ago (like databases) are now being written in Golang. Stuff like Caddy, Kubernetes, InfluxDB, etc.
- jpineman 10y agoe.g. Docker, too.
- makecheck 10y agoC and C++ are in use but it has become easier than ever to bridge in higher-level languages. It is also hard to code sanely on a large project without a higher-level language. Not every line of a program must be ultra-fast, and maintainability is still huge. If you are not offloading the less-critical parts of your project to languages that are easier to program in than C++, you are doing it wrong.
- aciliketcap 10y agoHello, I wrote an article about the other side of the coin, the problems I have with a world powered by C. https://www.linkedin.com/pulse/c-must-retire-sinan-akpolat?published=t https://www.linkedin.com/pulse/c-must-retire-sinan-akpolat?p... I don't want to compare C to another language. I just think that C is old.
- aciliketcap 10y agoHello, I wrote an article about the other side of the coin, the problems I have with a world powered by C. https://www.linkedin.com/pulse/c-must-retire-sinan-akpolat?published=t https://www.linkedin.com/pulse/c-must-retire-sinan-akpolat?p... I don't want to compare C to another language. I just think that C is old.