Live data from Hacker News

How can C Programs be so Reliable? (2008)

tratt.net

1–10 of 97 posts

Re: How can C Programs be so Reliable? (2008)

#2
Is the mindset of exception handling so different than robust C code? In both cases you have to choose to diligently handle errors and check the code/docs for all cases that can come up. Writing code with the occasional try/catch block isn't too different from writing C and not checking error conditions

Re: How can C Programs be so Reliable? (2008)

#3
Though not specific to C language, C.A.R Hoare's Retrospective: An Axiomatic Basis for Computer Programming provides insight on why Software is so reliable in spite of a lack of application of formal verification methods.

Retrospective: https://cacm.acm.org/opinion/retrospective-an-axiomatic-basi...

Here is a pdf of the retrospective along with the original paper : https://harrymoreno.com/assets/greatPapersInCompSci/2.2_-_An...

Re: How can C Programs be so Reliable? (2008)

#5

Though not specific to C language, C.A.R Hoare's Retrospective: An Axiomatic Basis for Computer Programming provides insight on why Software is so reliable in spite of a lack of application of formal verification methods. Retrospective: https://cacm.acm.org/opinion/retrospective-an-axiomatic-basi... Here is a pdf of the retrospective along with the original paper : https://harrymoreno.com/assets/greatPapersInCompSci/…

Here is another paper of his related to this:

How Did Software Get So Reliable Without Proof? C.A.R. Hoare 1996 (?) http://users.csc.calpoly.edu/~gfisher/classes/509/handouts/h...

Re: How can C Programs be so Reliable? (2008)

#6
1) were C programmers "better"? In sum total, pretty much.

2) C programs, at least the ones we use now, are a product of a lot of use and debugging

3) It didn't take too many debugging sessions as a C programmer to learn to program a bit more carefully.

4) and the more it gets used, the more error codes it encounters, and the more robust the handling gets. I think a dirty secret of software engineering isn't that the most complicated/heavily used code gets the most and most useful comments, it's that it also get the most error handling/detection code, and for the vast majority of non-core loop code: error handling ..isn't.

Re: How can C Programs be so Reliable? (2008)

#7
I think every graduating student should work on a non-trivial application in plain C for a year before moving on to another language.

It makes you exceptionally paranoid about failure states and practically requires a bit of thought and planning before attempting any non-trivial change.

The mindset of "it's fine to ignore all error conditions and let the default exception handler print a stack trace to the user" results in software that is annoying to the user.

Re: How can C Programs be so Reliable? (2008)

#8

Is the mindset of exception handling so different than robust C code? In both cases you have to choose to diligently handle errors and check the code/docs for all cases that can come up. Writing code with the occasional try/catch block isn't too different from writing C and not checking error conditions

> Writing code with the occasional try/catch block isn't too different from writing C and not checking error conditions

I think a critical difference is that in C the program is more liable to simply crash if errors aren't correctly handled, whereas in Java/Python/etc the program can just log a stack trace and keep on truckin', even if the bug is actually quite severe. In some cases a crash is preferable - e.g. if something goes wrong in a text editor while saving data, it's a lot better for the user if the program crashes versus the alternative where the editor runs as normal but saving doesn't work. Crashes in C also bring more urgency for developers to actually fix the bug compared to a try/catch in Python that simply buries it "until I get a chance to debug it properly." (But crashing also leads to a lot of frustration when the error wasn't that important and the C program should have just kept going.)

Re: How can C Programs be so Reliable? (2008)

#9
The author started by seriously admitting the drawbacks of C. Then, somehow, he says thanks to those flaws he has to pay higher attention when building software in C, he created very reliable tools.

That's something I can understand because when I wanted to buy a motorbike I was advised to ride a bicycle first since it's more difficult to control. Except that the White House called recently for companies to not use non memory safe languages such as C to build software.

Re: How can C Programs be so Reliable? (2008)

#10
Reliable is not the same as portable, which is not the same as well-defined according to the language spec.

The consequences of doing something incorrect or nonportable is sometimes that the expected behavior occurs. This can be validated by testing on the couple of platforms (or just one) that the program supports, and kept working.

Another thing we need to consider is that reliable is not the same thing as robust, let alone secure. A program that appears reliable to a user who uses it "as directed", giving it the expected kinds of inputs, will not necessarily appear reliable to a tester looking for ways to break it, or to a cracker trying to exploit it.

A truly reliable program not only handles all its functional use cases according to its requirements, but is impervious to deliberate misuse, no matter how clever.

Security flaws are found in reliable, well-debugged programs used in production by millions.

Post reply on HN