Live data from Hacker News

How can C Programs be so Reliable? (2008)

tratt.net

11–20 of 97 posts

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

#11

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

If you work with enough C code, you will come across exception handling. I made an exception handling library long ago. It lives mainly in Wireshark.

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

#12
C is horrible for exploratory programming but is acceptable if you already know how to solve the problem. If one uses enums for errors, then the compiler can check for you that all edge cases are handled. You can log an error and exit(1) for unhandled cases during development which makes it feasible to turn on -Werror but not have to implement every edge case up front.

You can do the same thing with tagged unions to implement a poor man's sum types. It is significantly more verbose than in a language that has syntactic support for this, but you get similar compile time safety guarantees.

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

#13

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 n…

That's not what the white house said and they're not an authority in software engineering anyway.

Just sensationalist journalism.

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

#14

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

[deleted]

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

#15
post #12

C is horrible for exploratory programming but is acceptable if you already know how to solve the problem. If one uses enums for errors, then the compiler can check for you that all edge cases are handled. You can log an error and exit(1) for unhandled cases during development which makes it feasible to turn on -Werror but not have to implement every edge case up front. You can do the same thing with tagged unions to…

> C is horrible for exploratory programming

Completely disagree. The lack of screwing around selecting abstractions forces you to make something productive right away and not stress about refactor.

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

#16

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,…

> 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.

A practical example of this is word size issues: A program that casts pointers to ints everywhere is perfectly reliable on 32-bit machines, but it will die horribly on any LP64 machine, which are most 64-bit machines. Related are endianness issues, which is why projects have tended to stop supporting big-endian systems: They're just too rare to scrounge up anymore, and unless you're actively testing on them, bugs can slip in which will not be caught on little-endian hardware.

Similarly, OS developers stop supporting architectures when they can no longer find working examples of them. This is because emulators have bugs, and without a source of truth (working hardware) it's very hard to determine if a bug you just found is in the OS or the emulator; add unreliable hardware to that and things just get worse. Bob Supnik (former DEC VP, creator of SimH) has a PDF:

http://simh.trailing-edge.com/docs/bugfeature.pdf

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

#17

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 n…

That's not what the white house said and they're not an authority in software engineering anyway. Just sensationalist journalism.

Is Stack Overflow also sensationalist journalism ?

https://stackoverflow.blog/2024/03/04/in-rust-we-trust-white...

In 6 hours, I will share the link to the official and related White House PDF document.

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

#18

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 n…

That's not what the white house said and they're not an authority in software engineering anyway. Just sensationalist journalism.

This is what the White House said: https://www.whitehouse.gov/wp-content/uploads/2024/02/Final-...

Interpreting this as "stop using C/C++" isn't much of a stretch. Yes, it is not a demand. Anticipating such a demand isn't a bad bet, however.

Who is an authority, anyhow? The White House is citing NIST, DHS, Microsoft, Cambridge DSCT, Google and others. Whom do you offer?

I don't like this myself. We're rapidly building tools that could conceivably solve memory safety in C/C++ code bases. I don't want C pilloried by Authority and its group thinking ways.

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

#19
post #12

C is horrible for exploratory programming but is acceptable if you already know how to solve the problem. If one uses enums for errors, then the compiler can check for you that all edge cases are handled. You can log an error and exit(1) for unhandled cases during development which makes it feasible to turn on -Werror but not have to implement every edge case up front. You can do the same thing with tagged unions to…

If you're talking about something like a web server, then sure. If you're talking about kernel hacking, then I completely disagree.

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

#20
post #12

C is horrible for exploratory programming but is acceptable if you already know how to solve the problem. If one uses enums for errors, then the compiler can check for you that all edge cases are handled. You can log an error and exit(1) for unhandled cases during development which makes it feasible to turn on -Werror but not have to implement every edge case up front. You can do the same thing with tagged unions to…

> C is horrible for exploratory programming Completely disagree. The lack of screwing around selecting abstractions forces you to make something productive right away and not stress about refactor.

Isn't "forced to make sth productive right away" the opposite of "exploratory programming"?
Post reply on HN