Live data from Hacker News

I cannot consistently write safe C/C++ code

robert.ocallahan.org

11–20 of 123 posts

Re: I cannot consistently write safe C/C++ code

#11
post #10
post #7

Earlier quoted context omitted.

Good risk management is about cost vs payoff analysis. To address the risk of car accident, first you stop juggling chainsaws while driving, then you start to wear seatbelts, and then you start thinking about how the remaining inevitable driving mistakes can be mitigated through technology or practices.

Sure. And the best "insurance" is having competent programmers.

Yes, competent drivers help, but I'm not sure a competent driver juggling chainsaws is better at driving than a bad driver not juggling chainsaws.

Re: I cannot consistently write safe C/C++ code

#12
post #10
post #7

Earlier quoted context omitted.

Good risk management is about cost vs payoff analysis. To address the risk of car accident, first you stop juggling chainsaws while driving, then you start to wear seatbelts, and then you start thinking about how the remaining inevitable driving mistakes can be mitigated through technology or practices.

Sure. And the best "insurance" is having competent programmers.

There seems to be no major C system not infested with errors most other languages forbid by design. The question is, do those other languages introduce their own types of errors? In my experience, no.

Do they fix all problems? Of course not. Neither does a hard hat.

Re: I cannot consistently write safe C/C++ code

#14

> I cannot consistently write safe C/C++ code. I'm not sure how to interpret what this means. What do "consistent" and "safe" mean? Is safety about not corrupting program data? Even when dealing with Python arrays, I can end up corrupting my arrays one way or another (off by one, race conditions, etc.). Is "consistent" about going days without a bug? Because I can't do that in any language. If not, what do these mean…

Of course every programming language is not perfect, including its library and related implementations.

In all of them is possible to introduce logical bugs.

The problem with C and its derived languages is that not only one has the logical bugs common to all programming languages, there are the memory corruption and UB introduced bugs to worry about as well.

While one can think as being super competent, make use of all tools to reduce such error cases, there are always situations where such errors get introduced due to fatigue, project pressure, continuous interrupts.

Additionally since most of us don't work alone, the actual code quality is an average of everyone that has ever worked on the code, and not everyone shares the same goals regarding quality of their work.

I share the feeling with the author, always tried to follow C and C++ best practices, when coding in C I adopted or evangelized tooling, safety standards or known books that lead to safer code.

Yet, like everyone else I had my share of memory corruption issues back on my C and C++ days.

One anecdote was trying to find out a memory leak that was bringing down a server in production, with the customer calling technical support every single day.

It took one week to track it down, and it wasn't something I would advise anyone to experiment.

Re: I cannot consistently write safe C/C++ code

#15
post #5

I think this whole "competent coders don't make mistakes" is a testament to the immaturity of the software development world. Real men write in assembly, maybe C if they're a bit tired. It would be like a construction worker saying "only noobs need a hard hat" or a surgeon refusing to wash their hands because they're careful never to touch anything contaminated. Or maybe simply refusing to wear your seatbelt because…

> Real men write in assembly, maybe C if they're a bit tired.

    root@boxen:~# cat > a.out

Re: I cannot consistently write safe C/C++ code

#16
post #5

I think this whole "competent coders don't make mistakes" is a testament to the immaturity of the software development world. Real men write in assembly, maybe C if they're a bit tired. It would be like a construction worker saying "only noobs need a hard hat" or a surgeon refusing to wash their hands because they're careful never to touch anything contaminated. Or maybe simply refusing to wear your seatbelt because…

> "competent coders don't make mistakes"

There's a bit of folklore that I can't remember correctly. One of the seven steps to becomming a hacker (in the pejorative sense) is this kind of overconfidence, not to make mistakes.

The last step is (the believe in) complete controle and omniscence. Another one, I guess, is insomnia.

It hang as a poster in informatics class - fond memories.

Re: I cannot consistently write safe C/C++ code

#17
post #3

Yet another subtle pro-Rust rant against C. Programming is hard, and writing safe code requires knowledge, not just in C, but in every single language. Even in formal-validable languages you can make mistakes: may be you'll not make errors by using sprintf, but can make others because of using a more complex language.

Rust does not appear in that page even once.

Re: I cannot consistently write safe C/C++ code

#18
> I cannot consistently write safe C/C++ code. I'm not ashamed of that; I don't know anyone else who can. I've heard maybe Daniel J. Bernstein can

For anyone that thinks this, you might be interested to find that DJB himself apparently thinks C, or at least the current state of C as implemented by the common compilers, is untenable for important, long lived software.[1] At least, that's how I interpreted his position. He was responded to as you would expect, unfortunately.

Credit where it's due. [2]

1: https://groups.google.com/forum/#!msg/boring-crypto/48qa1kWi...

2: https://news.ycombinator.com/item?id=14170585

Re: I cannot consistently write safe C/C++ code

#19
post #5

I think this whole "competent coders don't make mistakes" is a testament to the immaturity of the software development world. Real men write in assembly, maybe C if they're a bit tired. It would be like a construction worker saying "only noobs need a hard hat" or a surgeon refusing to wash their hands because they're careful never to touch anything contaminated. Or maybe simply refusing to wear your seatbelt because…

> Real men write in assembly, maybe C if they're a bit tired. root@boxen:~# cat > a.out

Laziness, impatience, and hubris.

  # zcat > /dev/kmem
Post reply on HN