Live data from Hacker News

Portability Is Reliability

evan.nemerson.com

11–20 of 26 posts

Re: Portability Is Reliability

#11
post #2

I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather…

> I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer.

But those layers are not part of your own work, they are external tools. Yes, it would be great if one of those would just catch all the bugs, but that's not happening.

So you have to choose either one single slice of Swiss cheese, or you work a bit on your plate to be able to add additional safeguards.

> Sure, a lot of the bugs in that C code are findable. But so what? However many bugs you uncover, you're unlikely to find them all, and even if you did then how would you know? So isn't fixing bugs in existing C codebases just throwing good money after bad?

Bug free is not achievable, in no language. But good enough, secure enough, functional enough are achievable goals.

For many existing code bases (especially for projects with clearly defined scope) good enough is easier achieved by fixing up C code compared to a rewite in a different language.

Was it a different language from the beginning it might have been cheaper overall, but at some point the rewrite will just consume more money to reach the same state.

Re: Portability Is Reliability

#12
post #2

I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather…

> never going to get you to 100% reliability

Both Atheist and Muslim SREs agree: Only god is 100% reliable.

Reasoning in non-absolute magnitudes is more effortful but usually more effective.

If 2 weeks of effort spent on the single layer would get it from 95% to 95.3% reliable, then you're likely better off with another layer. If 2 weeks of effort spent on the single layer would get it from 95% to 99.9% reliable, that seems like a wise choice. However, since your mental process for judging the reliability of a single layer is probably less than 99% reliable, adding another layer helps protect against unknown errors.

> So isn't fixing bugs in existing C codebases just throwing good money after bad?

I'd agree, with this train of thought:

The author says "in C, writing reliable software is somewhere between extremely difficult and impossible." To me, that sounds like writing in C is 2%-10% reliable. If writing in rust would be 40-80% reliable, that is a powerful argument for incrementally porting something to rust if that thing will continue to need to change.

Re: Portability Is Reliability

#13

Portability is complexity. Complexity is diametrically opposed to reliability.

A big part of the author's argument is 'portability is simplicity'. That's the reason why it produces more reliable code.

What is meant by that? I understand it like: don't write platform-specifc hacks. These rely on assumptions about behavior definitions for in general non-defined behavior.

An example: sometimes you can read meaningful data from memory after a free() because no one overwrote it. On your platform in your situation this can work.

It is clear for everyone that this is a bad idea. It would be great to have a low cost tool that tells you about such a bug. One class of tools for this are sanitizers. The author proposes another additional class of tools: testing your program with a run on another platform.

And why this could lead to more simplicity in the source code? A use-after-free bug comes from too much complexity. The programmer couldn't keep all the complexity in his or her mind. I bet in general well-written solutions without platform-specific assumptions look more simple and are better to understand for a human.

Clearer code because of more found bugs because of an extra bug-finding tool (cross-platform testing).

Re: Portability Is Reliability

#14
post #3

Eric Raymond, not Linus Torvalds, said the "given enough eyeballs" quote. Unfortunately there aren't enough eyeballs, so bugs linger for years anyway.

I don't know, lately I've been thinking maybe there are plenty of eyeballs and there's just too much code. Do things really need to be as big and complicated as they are?

Re: Portability Is Reliability

#15
post #2

I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather…

> I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. But those layers are not part of your own work, they are external tools. Yes, it would be great if one of those would just catch all the bugs, but…

> For many existing code bases (especially for projects with clearly defined scope) good enough is easier achieved by fixing up C code compared to a rewite in a different language.

I feel like this is because our standards for "good enough" are so low, partly because languages like C and C++ make it so hard to do any better. It's true that there is a high cost to switching languages for an existing project, but the cost we are paying for all of foundational tools and libraries being built in a shaky unsafe way is also huge.

Studies I've seen suggest that ~70% of security vulnerabilities in C and C++ codebases are bugs (memory safety, thread safety, undefined behaviour) that would be caught by static checks in other languages. Think how much time and effort goes into ensuring basic safety invariants in C codebases. Then think how many of the remaining logic bugs we could catch if that effort was spent entirely on finding them.

Re: Portability Is Reliability

#17

Portability is complexity. Complexity is diametrically opposed to reliability.

Aiming for portability doesn't always mean increasing complexity.

If it takes the form of #ifdef WIN32 directives then yes, you're increasing complexity in the name of portability, but if instead you're making an effort to avoid using platform-specific non-standard features, then that doesn't increase complexity, other than requiring developer discipline.

Re: Portability Is Reliability

#18
post #9

Earlier quoted context omitted.

> However many bugs you uncover, you're unlikely to find them all It is not specific to C/C++ - in any language there will be some bugs you're unlikely to find (before they are reported). > So isn't fixing bugs in existing C codebases just throwing good money after bad? You know you're inevitably going to have to rewrite it all eventually anyway If it took many years to write a big C codebase, then a rewrite likely w…

> It is not specific to C/C++ - in any language there will be some bugs you're unlikely to find (before they are reported). Perhaps (though frankly I doubt it). But at the very least it's very possible to avoid the "everything is a security bug by default" phenomenon of C/C++ undefined behaviour; your program may still crash occasionally, but a clean crash is relatively benign compared to security bugs or even just s…

> If a rewrite is necessary, then the sooner you start the sooner you'll finish.

A 8-person team might easily rely on more C/C++ code than could be rewritten by them in 3 years. This jumps to 10-40 years if you include external Open Source codebases like Nginx.

So, the team needs to prioritize and to do things in steps. While they are rewriting some C/C++ code, they'll need to still maintain other code.

...and they need to solve enough business problems to keep the lights on.

Re: Portability Is Reliability

#19
post #2

I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather…

You say that C / C++ is bad. You assume that there are alternatives that are just better. I think you are wrong.

Why? The short answer is: there is no free lunch. There is no silver bullet.

C / C++ has huge pitfalls with its memory management. But it is also a well-designed programming language with a great balance between efficiency and comprehensibility (and all other features of a language).

Every design decision in a language is a trade-off. And the trade-offs in C / C++ are so well chosen that there was no easy improvement for decades. No low hanging fruit. A C programmer has to understand much more about memory management because there is no virtual machine / garbage collector / interpreter running which takes care of it. But for that you get efficiency that is not possible by design with the other approaches.

For me C / C++ made the best trade-off.

Until Rust came along. Rust wants to make the memory management 10% better than C++ with 0% loss in efficiency. That is huge. No one reached something similar in 40 years. I am sceptical because this is such an ambitious undertaking. If that really works in real life I will be impressed.

Re: Portability Is Reliability

#20
post #2

I don't find the defence in depth approach appealing, because it's never going to get you to 100% reliability. Rather than adding six swiss-cheese layers and hoping the holes don't line up, it would be better to spend more time and effort on a single really solid layer. For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather…

> For the same reason, I don't find the argument for fixing bugs in C codebases at all compelling (at least if we're talking about "micro" bugs rather than overall architecture issues that might carry over to a future rewrite). Sure, there's a lot of C out there. Sure, a lot of the bugs in that C code are findable. But so what? However many bugs you uncover, you're unlikely to find them all, and even if you did then how would you know? So isn't fixing bugs in existing C codebases just throwing good money after bad? You know you're inevitably going to have to rewrite it all eventually anyway.

You're completely correct! The Linux kernel maintainers should stop bugfixing. It will be faster to rewrite it in a safer language than to add a one-line bugfix :-/

Oracle should also throw away their database code. As you say, it's faster to rewrite their 30m LoC database than to add a few lines of bugfixes.

Wait, hang on ... what about my volvo s/wagen? The various ECUs in it are all written in C! Certainly I don't want them to fix problems and roll out a patch next week. I'll wait the 5 years it takes for them to rewrite the entire system.

Then, of course, there's airliners. You're completely correct that we should not fix the problems in their code; we can shutdown air travel for the 8 years or so it takes to rewrite the system.

Gee, I wonder why everyone isn't as far-sighted and enlightened as you are.

Post reply on HN