3 ms·
> To be fair, most of the vulnerabilities found in C codebases are preventable with static analysis, bound checking, etc. You can work in an ad-hoc dialect of
by lmm 11y ago
> To be fair, most of the vulnerabilities found in C codebases are preventable with static analysis, bound checking, etc.
You can work in an ad-hoc dialect of C based on particular tools that will be a bit safer than standard C, sure (though probably still not as safe as an actually memory-safe language). But at that point most of the advantages of C no longer apply: you don't have a huge library ecosystem, you don't have a supply of experienced developers, you don't have a bunch of standard automated tools that work with your dialect.
> If you are ok with it getting as slow as Go, you can get similar safety guarantees as well.
There is no native/standard/supported-by-tools way to do tagged unions, so whatever you do C will always be less safe than languages that have native tagged unions.
- jjnoakes 11y agoI don't think "most of the advantages of C no longer apply [if you use static analysis or bounds checking]" is fair. Even if your claims about losing libraries, experienced developers, or automated tools was true (which think is false), you still get portability, close-to-the-metal code, full control of your processes, direct access to the native ABI, full access to the platform facilities, fast compilation, small executables, standalone libraries, memory layout control, ...
- lmm 11y agoC code is less portable than most of the alternatives. In the rare cases where the things you list are hard requirements there are still safer options e.g. Ada.
- jjnoakes 11y agoC code is less portable than which alternatives? As far as I know, most/all? alternatives are implemented in C or C++.
- lmm 11y agoPlenty of alternatives are self-hosting, but that's neither here nor there. Even if it's a major effort to port e.g. the Python interpreter to a new platform (particularly the first new platform - once you have a C codebase that enforces portability over many platforms it's much easier to add a new one). But that major effort has by and large been done for even relatively obscure languages and relatively obscure platforms. Whereas if you write in C you get to do that major effort for yourself for each program.
- jjnoakes 11y agoMore portable means "can be ported to new platforms more easily", not "has been ported to new platforms by someone else". A C program (in general) is more portable than anything written on top of C because to port, say, Python to a new platform, one has to have C there first. It has nothing to do with whether the work has been done by you or someone else. Of course, one can write code in either language which is not portable, but that is also beside the point.
- lmm 11y ago> A C program (in general) is more portable than anything written on top of C because to port, say, Python to a new platform, one has to have C there first. Port C compiler -> port your C program vs port C compiler -> port Python interpreter -> port your Python program. The latter can still end up a lot easier and cheaper, because the Python interpreter is already multi-platform and Python programs tend not to have much if any platform-specific code by the nature of the language. > It has nothing to do with whether the work has been done by you or someone else. It has everything to do with that. Ultimately via Turing equivalence it's possible to port anything to anywhere, so when we're talking about "portability" we must be talking about how much it costs to port a program to a new or existing architecture. > Of course, one can write code in either language which is not portable, but that is also beside the point. Again, it's very much the point, because it can't possibly be a yes-or-no thing. How costly is typical/idiomatic C code to port? How costly is typical/idiomatic Python code? Those are the questions that matter when we talk about language portability.