Live data from Hacker News

How can C Programs be so Reliable?

tratt.net

41–50 of 105 posts

Re: How can C Programs be so Reliable?

#41
post #39

Earlier quoted context omitted.

The later C standards add additional features. However, I'd argue that there is no such thing as a "great feature" in C++: almost everything in the language is a mistake, either intrinsically or in combination with other 'feature's. It's a blind pig with fifteen legs, trying to put on its own lipstick while riding a unicycle.

Spoken like someone who truly doesn't understand C. You even managed to confuse it with C++ (you might as well have said "Java" in the place of C++, it's about as close to C as C++ is) Well done. edit: Ignore this post. I misread. I'm an idiot. Sorry about that

I think you misread the comment you were responding to, and the comment that it was responding to.

Re: How can C Programs be so Reliable?

#42
post #37

Earlier quoted context omitted.

> Despite being the most popular form of employment for "programmers" it has always been the absolutely lowest form of life in a software ecosystem It just runs our banks, hospitals, governments... Much better to solely focus on those that write kernels, device drivers and filesystems?

So? Despite being useful, what's so interesting about CRUD programming for the enterprise? I've been there, I've had my share of dealing with coworkers that openly admit that they haven't touched a single book since graduation 10 years ago and they see no reason why would they want to. That's the kind of programmers this industry attracts, and that's the kind of software it builds. What's so interesting about it? Why…

> My ex-wife with zero programming experience has trained herself in less than a month to run a simple SQL queries in Visual basic and blast results in a grid control on a form, so did thousands of ex-taxi drivers in late 90s. So?

To be honest, I'm still not sure what point you're trying to make is. At best it's somewhat of an Ad Hominem attack.

Re: How can C Programs be so Reliable?

#43
> What I realised is that neither exception-based approach is appropriate when one wishes to make software as robust as possible.

The author misses the main point of exceptions: they let us separate data processing code from error handling code. This is why we are more productive in languages that have exceptions and our code is easier to maintain.

C requires us to handle errors throughout our program, tightly coupling the data processing code with the error handling code. With apologies to Mr. Spencer, I would declare that:

"Those who don't code in languages that lack exceptions are doomed to reimplement them, poorly."

Re: How can C Programs be so Reliable?

#44

Earlier quoted context omitted.

But oftentimes I want a correct result or an obvious failure, without having to handle tons of errors I don't even want to account for.

Returning -1 is an obvious failure. What you're saying is that you want your programs to blow up when a function returns a known error (such as "disk full"). One of the points of the article is that C makes you think about all the possible, well-documented, errors that each function can encounter. You know when you write C precisely what can go wrong at each stage, and decide the right way to handle it. Seeing a dial…

Defensive programming vs. `Let it fail`.

I think the space between to two is more uncomfortable than either extreme.

Re: How can C Programs be so Reliable?

#45
post #41
post #39

Earlier quoted context omitted.

Spoken like someone who truly doesn't understand C. You even managed to confuse it with C++ (you might as well have said "Java" in the place of C++, it's about as close to C as C++ is) Well done. edit: Ignore this post. I misread. I'm an idiot. Sorry about that

I think you misread the comment you were responding to, and the comment that it was responding to.

Yes, yes I did.

Re: How can C Programs be so Reliable?

#46
post #8

Earlier quoted context omitted.

The only time a function would "silently" return a -1 would be if you're not checking your returns for errors! Functions have return codes for a reason .

But oftentimes I want a correct result or an obvious failure, without having to handle tons of errors I don't even want to account for.

Exactly. In properly written C, about half your code is checking for errors and handling them explicitly. If you don't do that, at some point it will blow your foot off; you have to account for those errors. C programmers have generally accepted this and thus spend an excessive amount of coding time thinking about and writing recovery mechanisms for external errors -- and that's why so many C programs are incredibly stable.

Re: How can C Programs be so Reliable?

#47
post #40
post #37

Earlier quoted context omitted.

So? Despite being useful, what's so interesting about CRUD programming for the enterprise? I've been there, I've had my share of dealing with coworkers that openly admit that they haven't touched a single book since graduation 10 years ago and they see no reason why would they want to. That's the kind of programmers this industry attracts, and that's the kind of software it builds. What's so interesting about it? Why…

I think how interesting it is depends on your interest. If you are heavily into programming, as it seems you are, I can understand that SQL queries seem trivial and boring. If your interest is elsewhere programming is often just a tool used to create the interesting stuff. Whether that is usability, design, getting people to interact in new ways, launching rockets or automatically turning off your garden lights when…

But this article isn't about those things.

Re: How can C Programs be so Reliable?

#48
post #19

Earlier quoted context omitted.

if ((result = foo()) == -1) { fprintf(stderr, "!$*!$&^!$*!!!!\n"); exit(1); }

If exit() is too abrupt, you can always use setjmp() and longjmp() to set up a non-local jump to an error handler.

setjmp/longjmp is essentially what exception handlers do for you. I love C for its simplicity, but I'm not certain that leaving exception handling out of the language was a good idea. There are a lot of people who would agree with me there, including (I believe) a few Bell labs veterans who wrote the language in the first place.

Re: How can C Programs be so Reliable?

#49
post #36
post #30

Earlier quoted context omitted.

I use Linux, but I am still surprised it is really stable. At low level it's quite messed up and shows the cons of being a pseudo-bazaar ecosystem. Lately it's changing to a cathedral with a handful of core developers acting quite dictatorial and perhaps that will clean up things a bit. I'm not advocating any of both camps, just bringing up it is far from perfect. In particular I've spent last week trying to figure o…

In contrast, I consider the Linux kernel code clear and clean. I have mostly looked through the scheduling and file system code; I can't speak for TCP/IP port management.

Same here. I consider the Linux kernel code simple compared to systems code that I've dealt with in a professional environment.

Re: How can C Programs be so Reliable?

#50
post #30

Earlier quoted context omitted.

that was my experience when I went from ASM - to functional and then C when wrangling hardware. I am still surprised at how reliable C apps can be (linux kernel) - hats off to the genii involved in making things stable.

I use Linux, but I am still surprised it is really stable. At low level it's quite messed up and shows the cons of being a pseudo-bazaar ecosystem. Lately it's changing to a cathedral with a handful of core developers acting quite dictatorial and perhaps that will clean up things a bit. I'm not advocating any of both camps, just bringing up it is far from perfect. In particular I've spent last week trying to figure o…

There is an "aesthetic" to the kernel code I now realise (after having had it explained) - whilst some of it is no doubt odd looking, most of it is done that way for a reason, and reasonably consistently. But not to everyones taste.
Post reply on HN