Live data from Hacker News

How can C Programs be so Reliable? (2008)

tratt.net

61–70 of 97 posts

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

#61

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" resu…

When I was a student, I struggled learning algorithmic because we had to code in C. Luckily we had a wonderful teacher who listened to us, students, and switched his teaching to Pascal. That was a big relief to all of us.

I believe language like Pascal and Python are good to initiate you to algorithmic. After that, I agree you would need to dive into languages such as C, Rust and why not Assembly language to have a better understanding of your machine.

In our case, after one year of coding with Pascal, we spent the remaining years in focusing on C and C++ (Builder)

After that, it's time to move to pragmatic choices (job market requirements in terms ofdevelopment stack)

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

#62
post #24

Earlier quoted context omitted.

Well, there are such tools for C, but wouldn't using them be detrimental in this context? Think, like using a debugger vs. trying to wrap the execution in one's mind: I'not saying that one shouldn't use debuggers, but not using one has benefits, as a teaching device. Like running in a weight vest. Edit: ah, perhaps you meant, in addition to using raw C, one should also learn how to use such static analyzers & cie

As the author notes, to know what C code does you need to run it. A good debgger is a C programmers best friend.

Not necessarily:

> A year or two after I'd joined the Labs, I [Rob Pike] was pair programming with Ken Thompson on an on-the-fly compiler for a little interactive graphics language designed by Gerard Holzmann. I was the faster typist, so I was at the keyboard and Ken was standing behind me as we programmed. We were working fast, and things broke, often visibly—it was a graphics language, after all. When something went wrong, I'd reflexively start to dig in to the problem, examining stack traces, sticking in print statements, invoking a debugger, and so on. But Ken would just stand and think, ignoring me and the code we'd just written. After a while I noticed a pattern: Ken would often understand the problem before I would, and would suddenly announce, "I know what's wrong." He was usually correct. I realized that Ken was building a mental model of the code and when something broke it was an error in the model. By thinking about how that problem could happen, he'd intuit where the model was wrong or where our code must not be satisfying the model.

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

#63
post #31

Earlier quoted context omitted.

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

So it is worse, therefore it is better? Exceptions are exceptionally good at error handling - they always do the correct default (bubbling up if not handled, bringing a stacktrace with them, and by default they auto-unwrap the correct return value, not making the actual business logic hard to decipher), plus they make error handling possible on as wide scope as needed (try block vs a single return value). I absolutel…

Many years ago I started to dislike exception handling, probably because working in large software projects with many exceptions floating around.

Then a few years ago I started to write code in a primitive language without exception handling. I miss exceptions now.

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

#64
post #43

Earlier quoted context omitted.

What is stopping you from only using functions and structures in any language?

Java or C# required me to wrap every piece of code into class boilerplate (I think that has changed in the meantime, but just as an example). In C++, Visual Studio will bombard you with all sorts of silly C++ Core Guideline advice if you try to write simple and straightforward code. Finally, the standard libraries and 3rd party libraries might also get in the way if 'simple and straightforward' clashes with the idiom…

C# has been focusing on terseness for years now but is kept getting bundled together with Java :(

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

#65

Earlier quoted context omitted.

> were C programmers "better"? In sum total, pretty much No. Original programmers that just happened to use C were better, not the other way around.

I disagree. The early adopters are usually exceptional. When adoption grows the average level decreases. This is a well known phenomenon which is larger than just programmers. It was even on HN recently, as applied to IQs in high schools over time: as more kids reach high school, the average decreases. So yes. C programmers were better.

You’re literally proving my point and then summarizing with different conclusion.

They were exceptional because they were exceptional, not because they were C developers.

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

#66

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" resu…

C was the first language covered at my University back in the early 2000s

It was not a problem for me as I was learning Turbo C and Visual C++ 5/6.0 a year or two beforehand.

Everyone else in the class, though, were sooooo frustrated with their "89 errors, 103 Warnings" all because they forgot to add a semicolon in the code.

Truth is they were not getting anywhere to understanding how to write or care about the quality of the code.. leading to proper planning, etc. They would keep changing something to reduce the errors/warnings.

Personally, I think every person has their own journey into the world of programming. For me, I was happy for it to be C, with a bit of Pascal and Visual Basic. For someone else, perhaps Scheme and Javascript. Another maybe Java.

Some developers/programmers, in my opinion, are not for C. controversial ... I know.

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

#67
post #22
post #18

Earlier quoted context omitted.

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

At most, the White House's opinion on C/C++ will impact government contractors and people who care about the White House's opinion on matters it isn't qualified to speak about. I'd only be worried if I were in the business of selling software written in C/C++ to the government but a few campaign donations to politicians would probably get that fixed.

Most interesting parts of US government will buy and consume software written in C++ without qualification or reservation for the indefinite future. People are wishcasting, it isn’t a serious risk. New systems are being planned in C++ today and language choice isn’t even mentioned. Parts of government have a lot of experience with C++ in high reliability contexts.

There are many advanced systems in government written in C++ that would be impractical to deliver in any other language even if you were starting from scratch today. Extreme data intensity and throughput requirements are actually causing systems written in memory safe languages like Java to be replaced with C++ systems currently. Rust is often not a good fit for the software architectures required unless you are comfortable writing a lot of awkward unsafe code.

The government is pragmatic about programming languages, not ideological. They use both Rust and C++ in new systems but not for the same purpose, both have unique strengths in certain roles that ideologues are loathe to acknowledge. I use Rust and C++ the same way.

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

#68
post #40

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…

I built a house by only using a broken hammer, that made the house better because I needed to spend more time to handle the broken hammer correctly.

Not all comparisons fit.

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

#69

Earlier quoted context omitted.

Java or C# required me to wrap every piece of code into class boilerplate (I think that has changed in the meantime, but just as an example). In C++, Visual Studio will bombard you with all sorts of silly C++ Core Guideline advice if you try to write simple and straightforward code. Finally, the standard libraries and 3rd party libraries might also get in the way if 'simple and straightforward' clashes with the idiom…

C# has been focusing on terseness for years now but is kept getting bundled together with Java :(

I'm somewhat aware of the improvements, but at the same time I haven't seen much of that terseness in the real-world C# code I'm dealing with (typically Unity gameplay scripting code).

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

#70
post #31

Earlier quoted context omitted.

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

So it is worse, therefore it is better? Exceptions are exceptionally good at error handling - they always do the correct default (bubbling up if not handled, bringing a stacktrace with them, and by default they auto-unwrap the correct return value, not making the actual business logic hard to decipher), plus they make error handling possible on as wide scope as needed (try block vs a single return value). I absolutel…

[deleted]
Post reply on HN