Live data from Hacker News

How can C Programs be so Reliable? (2008)

tratt.net

1–10 of 230 posts

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

#3
Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.)

But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing it in Python? It seems like the codebase would be half as large.

In other words, is C the reason why Tarsnap is good, or is it because of Colin? Or is it both?

Example: Lisp, along with PG, is the reason why HN is good. Many of HN's features simply wouldn't be easily accomplished without it, so they wouldn't ever have been implemented. But I'm not sure the same could be said of Tarsnap.

But let's be honest - in how many languages can one retrospectively add a garbage collector?

Many. Lisp in particular. HN's links like /x?fnid=KxPuWC6qnkl4nxcUTDh4xs are an example of this.

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

#4

Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.) But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing…

/x?fnid=KxPuWC6qnkl4nxcUTDh4xs resolves to "unknown or expired link". Do you have a full URL?

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

#5

Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.) But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing…

> E.g. Lisp, along with PG, is the reason why HN is good. Many of HN's features simply wouldn't be easily accomplished without it

Could you expand/elaborate on this? I've never viewed HN as particularly complex, just tastefully designed with a good community.

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

#6
post #2

Adjusted for effort I don't know of any evidence that they are...

How does effort affect reliability? Even if you consider one as consequence of the other ("it requires more effort to make a reliable C program than the equivalent program in $language") that doesn't make the final product any less reliable.

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

#7
The author makes a good point about the discipline imposed by not having exceptions. Programmers tend to write code in one of two modes: the quick-and-dirty mode where you consistently don't check return values, or the built-to-last mode where you consistently do. If you start in the first mode and have to fix a bug, you often have to add error checking all up and down the call chain from where it occurs to where it's handle, so you very quickly migrate toward the second mode. By contrast, programmers in exception-based languages often get to a state where they catch some exceptions in some places where their tests have found bugs, but large sections remain in quick-and-dirty mode. The code tends to keep running longer after the actual error, leaving latent bugs that are harder to debug when they actually surface. The kinds of errors that are characteristic to C, such as segfaults from bad pointer handling, have obvious effects and more often have obvious causes as well.

I'm not totally anti-exception, and I think manual memory management is only appropriate in an increasingly small set of situations. I'd rather program in Python than C when I have the choice, but I acknowledge that the Python code I write is probably a bit less robust than the C code I write. I'm probably not alone. Theory aside, in practice the greater prevalence of sloppy error handling in languages other than C seems to leave the field pretty level when it comes to robustness.

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

#8

Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.) But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing…

Wait, HN is good? The community is interesting, but I've never been particularly impressed by the implementation. In particular, the "feature" where "More" links and such randomly expire after a while just screams "shoddy implementation" to me.

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

#9

Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.) But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing…

It's rarely the language that has any actual effect on the end result. The language is just a side show - the main story is about how well the developer understood the problem space and how well the abstractions and solutions he generated work to solve the problem.

Language can help a bit in making it clearer and giving the programmer more time to work on the important parts - but this actually goes both ways. Not having to worry about memory is a definite plus, but it can also be a big minus when you need to do something specific with that memory. For example, mutating in place is very easy in C when its required, but trying to mutate in place in some of the newer languages is very difficult.

Also it's doubtful if Tarsnap would be better if it was in Python. It might (or might not, depending on optimizations) have been quicker to write it originally in Python - but nobody would trade an already created C tarsnap for a Python tarsnap because the Python one would use more ram and run slower.

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

#10

Tarsnap is the classic example of a C program whose reliability almost defies belief. Its codebase is large; it solves a very hard problem; and it manages to handle almost every cornercase flawlessly. (As of the latest version, it seems to handle every cornercase flawlessly, as far as I know.) But I've always wondered: if Colin were as experienced with Python as he is with C, would Tarsnap be better served by writing…

/x?fnid=KxPuWC6qnkl4nxcUTDh4xs resolves to "unknown or expired link". Do you have a full URL?

It got garbage-collected. That's the point.
Post reply on HN