jasonthorsness
13 hours ago
“None of the safe programming languages existed for the first 10 years of SQLite's existence. SQLite could be recoded in Go or Rust, but doing so would probably introduce far more bugs than would be fixed, and it may also result in slower code.”
Modern languages might do more than C to prevent programmers from writing buggy code, but if you already have bug-free code due to massive time, attention, and testing, and the rate of change is low (or zero), it doesn’t really matter what the language is. SQLIte could be assembly language for all it would matter.
oconnor663
13 hours ago
> and the rate of change is low (or zero)
This jives with a point that the Google Security Blog made last year: "The [memory safety] problem is overwhelmingly with new code...Code matures and gets safer with time."
https://security.googleblog.com/2024/09/eliminating-memory-s...
miohtama
8 hours ago
You can find historical SQLite CVEs here
https://www.sqlite.org/cves.html
Note that although code matures the chances of C Human error bugs will never go to zero. We have some bad incidents like Heartbleed to show this.
hnlmorg
6 hours ago
Heartbleed was a great demonstration of critical systems that were under appreciated.
Too few maintainers, too few security researchers and too little funding.
When writing systems as complicated and as sensitive as the leading encryption suite used globally, no language choice will save you from under resourcing.
ziotom78
7 hours ago
Right, but I believe nobody can claim that Human error bugs go to zero for Rust code.
john_the_writer
5 hours ago
Agreed. I rather dislike the idea of "safe" coding languages. Fighting with a memory leak in an elixir app, for the past week. I never viewed c or c++ as unsafe. Writing code is hard, always has been, always will be. It is never safe.
simonask
5 hours ago
This is a bit of a misunderstanding.
Safe code is just code that cannot have Undefined Behavior. C and C++ have the concept of "soundness" just like Rust, just no way to statically guard against it.
gcr
an hour ago
Modern compilers like clang and GCC both have static analysis for some of this. Check out the undefined behavior sanitizer.
azornathogron
2 minutes ago
It's certainly true that there are static analysis tools for C and C++, but the undefined behavior sanitizer is not one of them.
UBSan adds extra runtime checks to detect various kinds of undefined behavior. Static analysis means analysing the program at compile time, not runtime. Static analysis is typically comprehensive in a way that runtime checks are not. For example if you have a static analysis that verifies that a particular array access is in-bounds, then you can be confident that that is always true no matter what inputs the program receives. Whereas if you have a runtime check for the array access, it doesn't tell you anything except about the specific executions that you've actually run. Therefore runtime checks either need to be enabled in production/released code, or you need to rely on test coverage to make sure you're actually exercising the different possible execution paths of the code so that you have the best chance that the runtime check will catch bugs.
Testing is good regardless, but if you can eliminate a class of programming error comprehensively by static analysis, then that's great because that's one kind of error that you no longer have to invest effort in testing for. And it's also more effective because comprehensive test coverage is rare in practice, and difficult in theory. Program state space and the number of different possible execution paths is just too huge, so you have to rely on grouping "similar" states and "similar" execution paths - these are your test cases - but it's still mostly up to the human programmer to come up with them or use things like coverage directed fuzzers (good, but still not guaranteed to find all different cases), etc
humanrebar
18 minutes ago
Sanitizers are technically dynamic analysis. They instrument built programs and analyze them as they run.
jen20
24 minutes ago
A memory leak is not a memory safety issue.
devjab
4 hours ago
I quite like that Zig works a drop in for C in a few use cases. It's been very nice to utilize it along with our Python and regular C binaries. We attempted to move into Go because we really like the philosophy and opinions it force upon it's developers, but similar to interpreted languages it can be rather hard to optimize it. I'm sure people more talented than us would have an easy time with it, but they don't work for us. So it was easier to just go with Python and a few parts of it handled by C (and in even fewer cases Zig).
I guess we could use Rust and I might be wrong on this, but it seemed like it would be a lot of work to utilize it compared to just continuing with C and gradually incorprating Zig, and we certainly don't write bug free C.
Hendrikto
2 hours ago
> We attempted to move into Go […], but similar to interpreted languages it can be rather hard to optimize it. […] So it was easier to just go with Python
I don’t get that. You had trouble optimizing Go, so you went with Python?
actionfromafar
2 hours ago
Python + C. Probably C for the optimized parts.
ChrisRR
3 hours ago
This is the argument against re-writing the linux base utils in rust. When they've had such widespread use for decades, a hell of a lot of bugs have been ironed out
bombcar
3 hours ago
Especially since memory bugs are only a subset of all bugs, and (perhaps) not even the most important subset.
Memory bugs are often implicated in security issues, but other bugs are more likely to cause data loss, corruption, etc.
weinzierl
6 hours ago
"SQLite could be recoded in Go or Rust, but doing so would probably introduce far more bugs than would be fixed, and it may also result in slower code."
We will see. On the Rust side there is Turso which is pretty active.
Sammi
4 hours ago
The Sqlite team in stuck in the classic dilemma. They are stuck with their existing thing because it is so big, that you can't just stop the world for you existing users and redo it. Meanwhile some small innovator comes along and builds the next thing because why not, they don't have anything holding them back. This is classic Innovator's Dilemma and Creative Destruction. This has of course not happened yet and we have to wait and see if Turso can actually deliver, but the Turso team is extremely talented and their git repo history is on fire, so it is definitely a possible scenario.
pjmlp
3 hours ago
The author cleverly leaves out all the safer alternatives that have existed outside UNIX, and what was happening with computers outside Bell Labs during the 1970's.
Not only was Apple was able to launch the Mac Classic with zero lines of C code, their Pascal dialect lives on in Delphi and Free Pascal.
As one example.
wat10000
an hour ago
Isn’t Pascal just as problematic as C in this respect? And the original Mac was mostly (all?) assembly, not Pascal. They couldn’t have used a higher level language anyway. The system was just too small for that. SQLite wouldn’t fit on it.
pjmlp
an hour ago
Not at all, because Pascal is more strongly typed, and has features that C is still yet to acquire in type safety.
Non exaustive list:
- proper strings with bounds checking
- proper arrays with bounds checking
- no pointer decays, you need to be explicit about getting pointers to arrays
- less use cases of implicit conversions, requires more typecasts
- reference parameters reduce the need of pointers
- variant records directly support tags
- enumerations are stronger typed without implicit conversions
- modules with better control what gets exposed
- range types
- set types
- arenas
There was plenty of Pascal code on Mac OS including a Smalltalk like OOP framework, until C++ took over Object Pascal's role at Apple, which again it isn't C.
I love the "but it has used Assembly!" usual rebutal, as if OSes written in C weren't full of Assembly, or inline Assembly and language extensions that certainly aren't C (ISO C proper) either.
If you prefer, Zig is a modern taken on what Modula-2 in 1978, and Object Pascal in the 1980's already offered, with the addition of nullable types and comptime as key differentor in 40 years, packaged in a more appealing syntax for current generations.
wat10000
an hour ago
My point is that the original Mac used little to no Pascal. The assembly isn’t a “rebuttal,” it’s just what was actually used.
nabhasablue
7 hours ago
there is already an sqlite port in Go :) https://gitlab.com/cznic/sqlite
ncruces
4 hours ago
That's not a port. That's an extremely impressive machine translation of C to Go.
The output is a non-portable half-a-million LoC Go file for each platform.
ahoka
4 hours ago
Sure they did exist, almost no one cared though.
pizza234
5 hours ago
> you already have bug-free code due to massive time, attention, and testing, and the rate of change is low (or zero), it doesn’t really matter what the language is. SQLIte could be assembly language for all it would matter.
This is the C/++ delusion - "if one puts enough effort, a [complex] memory unsafe program can be made memory safe"; the year after this page was published, the Magellan series of RCEs was released.
Keeping SQLite in C is certainly a valid design choice, but it's important to be aware of the practical implications of the language.