by gigaflops · 3y ago · 0 comments
Yet everyone’s idea of safety still seems to be “just write bug-free C code, bro”.
Does it though? I think "the industry" has pretty much come around on C being unsafe, and generally not a great choice of language for new projects.
But the fact is that there's a lot of C code out there, and we can't just ditch or rewrite it all overnight. In an ideal world, we wouldn't be starting from here. But we are, and it's going to take time to get to where we need to be.
Heck, take a look at the recent story about "Considering C99 for curl": https://news.ycombinator.com/item?id=33704054
From the linked article:
> The slowest of the “big compilers” to adopt C99 was the Microsoft Visual C++ compiler, which did not adopt it properly until 2015 and added more compliance in 2019. A large number of our users/developers are still stuck on older MSVC versions so not even all users of this compiler suite can build C99 programs even today, in late 2022.
What are the chances that the kinds of people who are still doing development on systems where the C compiler is from 2015 or earlier, or on a more niche system that Windows that lots of new safe languages haven't been ported to yet (and such ports aren't even on the radar), are going to able to start moving to developing in rust or whatever anytime soon?
If you look at some of the Rust threads on HN right now [0], you find many commenters claiming that there is no reason to replace C with Rust. It could be a vocal minority, but there's still a sense that "not everyone is on board".
I actually don't see many claim that in that thread. There are 196 comments and I didn't read all of them, but only one greyed-out top-level comment says so, and what I can skim from the other comments I don't really see a whole lot of people say "C is fine!"
There are some concerns about performance, and some other comments about (alleged) "Rust spam", but that's not the same as "C is fine!"
In my experience "C is unsafe" was already generally agreed on about 20 years ago, which is one reason many choose Java, Python, PHP, etc. at the time. It wasn't a universal consensus, but if you were to take a poll in 2003 I bet it would be well over 50%.
Those are just people annoyed that their knowledge is getting outdated, and grasping for any medium-approved excuse to not learn the new thing. Those believe that Rust will replace C, they just don't like it.
(Anyway, C, like COBOL, won't just die. There's no reason to be afraid.)
Yeah but do they like the language tho.
If you have some reason to choose C today, I'm not sure Rust is a contender to stand in as a replacement. They are vastly different languages. That doesn't mean there is rejection that C's memory model is unsafe, just that there isn't a "better C" recognized to choose from.
Because otherwise, you could write Rust 2018 edition (for example), and there's nothing preventing a situation where your currently-valid Rust-2018-edition program stops compiling (or behaves differently) on a future version of rustc even when compiling to that specific edition, just because some behavior is (in the future) considered a compiler bug or something. And it would be perfectly valid to cause such breakage, because there's no definition of "what is Rust", other than "what this specific compiler in this specific version accepts".
I'm not talking about whether such possible backwards-incompatible change on a Rust edition would be good or bad. Just that with the current monoculture around a single implementation, there's not many guarantees.
A specification, or multiple implementations, would at least add some (good) friction.
I'm not denying its current value as a safe language; just that, as it is now, I don't consider it as a good choice for programs that must stay alive for decades, like `curl` or an operating system.
It seems like "write memory safe C" was the best technique in 1996 if you wanted any semblance of portability/performance.
... still have multiple easily-uncovered memory issues.
Nobody writes safe C. Believing otherwise is delusional. This has been known for decades. But many believers still exist.
Common Lisp, depending on how you define memory safety.
If you remove the 'still exist today with meaningful market share', in '96 you had more options (e.g. Modula-2/2+/3 family).
There were others.
Unfortunately it still lacks meaningful marketshare though.