News for hackers. Stuff that matters.
Re:How can C Programs be so Reliable? by stygianguest on Thursday September 22, 2011 @05:41AM (#3025460)
I would contend that C does very little in the way of preventing errors and debugging them if they occur. The claim that "[..] only two C-specific errors have thus far caused any real problem in the Converge VM," is completely beside the point. Language specific errors have never been the problem. Java's infamous null-pointer exceptions are not java specific: the C equivalent would be a segfault. And please do note, that Java prints a stack trace by default to help correct the mistake. A huge step forward from C's generic segfault.

The real reason that most C programs in daily use are so robust, is because they are ages old. Many, many man-years have been invested in the production of e.g. BSD, unix tools, POSIX libraries, and even web browsers and word processors.

Why do we use Javascript and even PHP to program web-applications? Because we need fewer lines to get the same result. Moreover, given the correlation between number of lines and number of bugs, shorter programs are better. If we had been limited to C "web 2.0" would have been decades away.

Re:How can C Programs be so Reliable? by tobiasu on Thursday September 22, 2011 @06:42AM (#3025574)
A nullpointer exception in java is the exact same notification that C gets. A segmentation fault has nothing to do with C, it's an exception raised by the CPU. Printing a stack trace also has zero to do with C, but I would bet that the code generating the trace information in the JVM and others is usually written in C, as is the signal handler that handles it.

It is amazing that the people who rely on high-level languages think they can stomp on lower-level languages like this, without even realizing that virtually _all_ the features they talk about are made possible by low level languages and are implemented in them.

New C programs get written all the time. They work. They move your world, every day, like clockwork.

Re:How can C Programs be so Reliable? by apaprocki on Thursday September 22, 2011 @10:35PM (#3028618)
I'm glad some people reading this thread have a better perspective. It's actually kind of shocking how many people talk about C as if no one uses it anymore. "In the old days..."
Re:How can C Programs be so Reliable? by nickolai on Thursday September 22, 2011 @06:10AM (#3025514)
Provided the binary has a minimum of debugging symbols, you can get a meaningful backtrace from a core dump of a C program. It is very similar to the java stack trace. You can even get the value of the parameters, which AFAIK, java doesnt do.
Re:How can C Programs be so Reliable? by Roboprog on Thursday September 22, 2011 @12:36PM (#3026641)
Assuming the core wasn't dumped as a result of secondary damage, causing a completely correct line of code to be shown at the top of the stack trace.

At least with Java, pointers/references/objects are either null, or valid. Uninitialized references won't compile, and a null dereference blows stack at point of first use.

Having said that, I like pointer and bounds checking, but wish Java had significant memory management options, for times when you were willing to trade some safety for speed.

Re:How can C Programs be so Reliable? by p9idf on Thursday September 22, 2011 @06:23AM (#3025536)
"Java prints a stack trace by default to help correct the mistake, a huge step forward from C's generic segfault."

A segfaulting program will dump core, which the programmer can use to get the stack trace. I consider this to be better UI than printing the trace at a likely bewildered user.

Re:How can C Programs be so Reliable? by adobriyan on Thursday September 22, 2011 @06:28AM (#3025550)
Distros ship with "ulimit -c" being 0, so no, it won't dump core.
Re:How can C Programs be so Reliable? by piotrSikora on Thursday September 22, 2011 @06:41AM (#3025573)
Blame your distribution for that, not C... On OpenBSD "it just works (tm)":

  $ ulimit -c
  unlimited
Re:How can C Programs be so Reliable? by eru on Thursday September 22, 2011 @06:54AM (#3025597)
Although for most Linux users nowadays a limit of zero is the Right Thing.
Re:How can C Programs be so Reliable? by burgerbrain on Thursday September 22, 2011 @11:28AM (#3026374)
...Which means that only the people who want coredumps/stacktraces get them. Instead of everyone.

Sounds like a feature.

Re:How can C Programs be so Reliable? by sunkencity on Thursday September 22, 2011 @07:54AM (#3025730)
Ah, interesting information nugget! I have been wondering why there's no core dumps around in linux any more, in the old days when I used redhat & mandrake the fs would be littered with them.
Re:How can C Programs be so Reliable? by 0x12 on Thursday September 22, 2011 @06:07AM (#3025504)
Think of javascript and PHP as DSLs for web development written on top of C. Their reliability and conciseness is an indirect proof of the authors main point.

C allows you to write interpreted languages that execute with a speed high enough to afford you more abstraction.

Re:How can C Programs be so Reliable? by whateverer on Thursday September 22, 2011 @11:24AM (#3026361)
That's a bit too cheer-leady of C, and stretches the definition of DSL way too much. Ruby didn't suddenly become a Java DSL when it was ported to the JVM, neither did Perl become a Haskell DSL when Pugs was written.

Let's give credit where it's due, but really C could have been Ada in any of those examples and the results would have been about the same (especially in PHP's case).

Re:How can C Programs be so Reliable? by gaius on Thursday September 22, 2011 @06:21AM (#3025529)
A huge step forward from C's generic segfault.

This is straightforward enough in C: http://gaiustech.wordpress.com/2011/09/09/segmentation-fault...

Re:How can C Programs be so Reliable? by EdiX on Thursday September 22, 2011 @09:42AM (#3026022)
valgrind doesn't dump registers but doesn't require special compilation options and if debugging symbols are available will include file names and line numbers in the stack trace.
Re:How can C Programs be so Reliable? by tolmasky on Thursday September 22, 2011 @06:09AM (#3025510)
Obviously I have no hard data on the reliability of new C programs, but things like git (which I at least find pretty reliable) may serve as counter point to this theory.
Re:How can C Programs be so Reliable? by rkangel on Thursday September 22, 2011 @07:03AM (#3025610)
Don't forget that only the core of Git is C, the rest is big pile of shell scripts, and (I believe) perl.
Re:How can C Programs be so Reliable? by burgerbrain on Thursday September 22, 2011 @03:36PM (#3027450)
This is not particularly the case. Things with git are initially implemented as shell scripts, as a way of "just getting it done", but are later migrated to C. These days a very large portion of Git is straight C.
Re:How can C Programs be so Reliable? by davvid on Thursday September 22, 2011 @06:13PM (#3028030)
Much of the early git scripts (e.g. git-pull) have been rewritten in C. Performance is one reason. Helping out win32 (where fork+exec is slow) is another.

  $ ls -1 git-*.sh | wc -l
        25
  $ ls -1 git-*.perl | wc -l
         9
Compare this to the built-in commands:

  $ ls -1 builtin/*.c | wc -l
        92
or all the C files:

  $ git ls-files '*.c' | wc -l
       306
Re:How can C Programs be so Reliable? by nl on Thursday September 22, 2011 @09:34PM (#3028496)
I suspect the authors of Git are - on average - more competent than the average developer.