News for hackers. Stuff that matters.

Why do we use C still?

Why do we use C still when there are other languages like Go or C++ or even D? BCPL and B were done away with so quickly, so why do we still use C in our modern society with languages that can do things a lot more efficiently?
( 21 comments | 12 points | on HN )
Re:Why do we use C still? by angersock on Thursday April 26, 2012 @11:41PM (#3897402)
Some reasons:

1. Everyone has a C compiler, or can write a decent-enough one to support their preferred environment.

2. C is well tested and specified. Reading the standard isn't an exercise is face melting (compare with, say, C++).

3. As a systems language, C doesn't require a runtime library if not needed, and this can be left out very easily (not the case with Go, D, or C++, as I'm aware).

4. C exposes easy trapdoors to the underlying machine (inline assembly, pointers, etc.) that are very handy.

5. C is usable by other languages, as its calling conventions are well documented. This is why C is a preferred base language for things like OpenGL bindings--it's easy to write Ruby, Pyhton, Java, etc. wrappers. This is in sharp contrast to C++, which is brainfucked for things like symbol exports.

6. A line of C is pretty obvious in what it does, when written correctly. You can usually estimate what code it'll generate, barring #define hackery. C++ especially is bad at this.

~

C is still used because it doesn't do a lot, and it nails what it does do.

Re:Why do we use C still? by drallison on Thursday April 26, 2012 @08:36PM (#3896847)
C is an adequate language (actually, more than adequate) with a large base of skilled programmers. There is a long history of successful development. And the developer base is aware of the warts that still remain in the language.
Re:Why do we use C still? by netbyte on Thursday April 26, 2012 @08:38PM (#3896855)
But why use C when there are other Systems programming languages like Go, C++, D, etc..
Re:Why do we use C still? by chipsy on Thursday April 26, 2012 @08:54PM (#3896910)
You can compile programs with those languages and get something that works, but on a regular basis, some programmer will say something like, "Ok, I'll use Go for project x" and get part of the way into it and then discovers...

...a critical library has not been ported.

...a really useful language feature doesn't exist, or its implementation isn't appropriate for this application.

...a compiler bug appears and causes days to weeks of torment.

...it's difficult to deploy and distribute the result.

...there are fewer tools, debugging aids, etc.

Languages don't live in a "clean room" environment. All of these things add value even when the language itself is unsound. And then you weigh the cost of rolling new tools, fixing the compiler yourself, etc. against building on the old stuff, and the old stuff wins most of the time. Reaching the opposite conclusion is the exception, and to get there, the language usually has to carve out a niche use-case where it has the best library for a certain domain.

Re:Why do we use C still? by tonteldoos on Thursday April 26, 2012 @08:53PM (#3896903)
One reason would be the massive existing codebases written in C (Linux kernel, anyone?)...
Re:Why do we use C still? by paolopatron on Thursday April 26, 2012 @09:04PM (#3896949)
We should all switch to Java/C#. It makes programming much much faster and easier. http://techiest.blogspot.com/.
Re:Why do we use C still? by joezydeco on Thursday May 10, 2012 @03:03PM (#3955302)
I work on embedded microcontrollers that have, at the most, 16K of code space and 512 bytes of RAM. I have a nice efficient optimizing C compiler that creates object code nearly as tight as the local assembly language.

Do you think I would benefit from Java? Because I don't.

Re:Why do we use C still? by tonteldoos on Thursday April 26, 2012 @11:17PM (#3897341)
And the resulting code much slower too. It all depends on what you want to accomplish. Really, THIS particular topic has substantial bandwidth allocated to it already...
Re:Why do we use C still? by nnoitra on Thursday April 26, 2012 @11:00PM (#3897302)
The only way to do elegant programming is with C. C is as perfect as programming languages can get. The other languages that you named are just more flawed than C. That's why.
Re:Why do we use C still? by frou_dh on Friday April 27, 2012 @09:23AM (#3898880)
Ah yes, I'm sure the Go designers in particular are ignorant about the pros and cons of C </s>
Re:Why do we use C still? by khyryk on Thursday April 26, 2012 @09:13PM (#3896977)
Generally, the good reasons you'll see for using C are lack of C++ compiler availability and embedded programming.

The bad reasons tend to be variations of developer inertia and the inability to decide which features of C++ ought to be used -- arguing against the STL isn't a good argument against C++ as a whole.

Re:Why do we use C still? by netbyte on Thursday April 26, 2012 @09:40PM (#3897067)
On Linux/Mac you have g++ and on Windows you have MinGW/Visual Studio
Re:Why do we use C still? by khyryk on Thursday April 26, 2012 @09:58PM (#3897125)
There are many more operating systems out there.
Re:Why do we use C still? by lsiebert on Friday April 27, 2012 @12:32PM (#3899832)
C is currently the language I know best. I may therefore be biased. There are multiple reasons why C is useful for system programming. Legacy code as others have said. A huge community for support and maturity in tools. The fact that C is very close to the bare metal of the system, which means that problems with your code like memory leaks are most likely the programmer's fault , and can thus be fixed by the programmer. It also isn't proprietary in any way. There is no for profit company that controls the language.

C has disadvantages. But many of them are the result of its advantages. Automated garbage collection is great, but garbage collection by hand tuning code gets stuff that AGC may miss.

That said, I'm interested in picking up some of the other languages mentioned.

Re:Why do we use C still? by dubya on Friday April 27, 2012 @10:12AM (#3899096)
I use C as a language of last resort, as a sort of universal assembly language. If I get a problem to the point that I know exactly what I want the machine to do, but can't convince Haskell or Python or Java to do it and don't have the time to research a proper solution, I can knock something out in C that will be as fast as the machine can reasonably be expected to go. It erases all of the questions about whether the compiler is doing something mysterious to sabotage you.
Re:Why do we use C still? by melling on Thursday April 26, 2012 @09:39PM (#3897065)
Because the Go compiler doesn't optimize good enough yet?

It seems like the one language that might replace C/C++ in many instances. My favorite feature is the incredible compile times.

http://golang.org/

Re:Why do we use C still? by chc on Friday April 27, 2012 @03:12PM (#3900632)
Ironically, your favorite feature is also your least favorite feature: The compiler is relatively simple and unambitious, resulting in fantastic compile times. Once you start doing advanced analysis and multiple passes, you suddenly aren't so speedy anymore.
Re:Why do we use C still? by Glowbox on Thursday April 26, 2012 @08:46PM (#3896882)
Just search for 'C++ for kernel' on google. There are plenty of reasons. A good answer can be found here: http://stackoverflow.com/a/520355
Re:Why do we use C still? by eli_gottlieb on Thursday April 26, 2012 @11:56PM (#3897457)
Re:Why do we use C still? by remixhacker on Thursday April 26, 2012 @10:40PM (#3897242)
because C is perfection
Re:Why do we use C still? by checkers on Thursday April 26, 2012 @10:46PM (#3897262)
Nope, Java/C# is PERFECTION. http://techiest.blogspot.com/.