Hacker News new | ask | show | jobs
by legulere 1876 days ago
Portability is complexity. Complexity is diametrically opposed to reliability.
2 comments

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

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.