Live data from Hacker News

Why Is SQLite Coded In C

sqlite.org

281–290 of 411 posts

Re: Why Is SQLite Coded In C

#281

Earlier quoted context omitted.

> Any language, including C, will emit or not emit instructions that are "invisible" to the author Presumably this is why they do 100% test coverage. All of those instructions would be tested and not invisible to the test suite

How could they know? Any changes to the compiler will potentially generate new code. A new compiler, new flags, a new version. These all can create new invisible untested branches.

The way you know is by running the full SQLite test suite, with 100% MC/DC coverage (slightly stricter than 100% branch coverage), on each new compiler, version, and set of flags you intend to support. It's my understanding that this is the approach taken by the SQLite team.

Dr. Hipp's position is paraphrased as, “I cannot trust the compilers, so I test the binaries; the source code may have UBs or run into compiler bugs, but I know the binaries I distribute are correct because they were thoroughly tested" at https://blog.regehr.org/archives/1292. There, Dr. John Regehr, a researcher in undefined behavior, found some undefined behavior in the SQLite source code, which kicked off a discussion of the implications of UB given 100% MC/DC coverage of the binaries of every supported platform.

(I suppose the argument at this point is, "Users may use a new compiler, flag, or version that creates untested code, but that's not nearly as bad as _all_ releases and platforms containing untested code.")

Re: Why Is SQLite Coded In C

#282
post #186

Earlier quoted context omitted.

I think Rust (and C++) are just too complicated and visually ugly, and ultimately that hurts the maintainability of the code. C is simple, universal, and arguably beautiful to look at.

C is so simple, that you will need to read a 700-page, comitee-written manual befor you can attempt to write it correctly.

> C is so simple, that you will need to read a 700-page, comitee-written manual befor you can attempt to write it correctly.

The official C99 standard document is typically about 210 pages.

Re: Why Is SQLite Coded In C

#283

Earlier quoted context omitted.

Right, but I believe nobody can claim that Human error bugs go to zero for Rust code.

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.

A memory leak is not a memory safety issue.

Re: Why Is SQLite Coded In C

#284
post #157

Earlier quoted context omitted.

No, but as morbid as this sounds, the three(?) devs one day will pass away so now what?

Then the rights will be sold to a FAANG or an open souce fork like libSQL will live on.

SQLite is public domain (as much as is legally possible). So there's no "rights" to "sell" except the trademark.

Re: Why Is SQLite Coded In C

#285
post #273

Earlier quoted context omitted.

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.

Modern compilers like clang and GCC both have static analysis for some of this. Check out the undefined behavior sanitizer.

Sanitizers are technically dynamic analysis. They instrument built programs and analyze them as they run.

Re: Why Is SQLite Coded In C

#286
Back in the good ol'/bad ol' days of the very early web/Internet, I had the fortune of working with someone who, lets say, has kind of a background in certain operating systems circles.

Not only had this fellow built a functional ISP in one of the toughest markets (at that time), in the world - but he'd also managed to build the database engine and quite a few of the other tools that ran that ISP, and was in danger of setting a few standards for a few things which, since then, have long since settled out, but .. nevertheless .. it could've been.

Anyway, this fellow wrote everything in C. His web page, his TODO.h for the day .. he had C-based tools for managing his docs, for doing syncs between various systems under his command (often in very far-away locations, and even under water a couple times) .. everything, in C.

The database system he wrote in pure C was, at the time, quite a delight. It gave a few folks further up the road a bit of a tight neck.

He went on to do an OS, because of course he did.

Just sayin', SQLite devs aren't the only ones who got this right. ;)

Re: Why Is SQLite Coded In C

#287

Earlier quoted context omitted.

Because C's assert gets compiled out if you have NDEBUG defined in your program. How do you do conditional compilation in Go (at the level of conditionally including or not including a statement)?

> How do you do conditional compilation in Go (at the level of conditionally including or not including a statement)? https://stackoverflow.com/questions/36703867/golang-preproce... Wouldn't this work? Surely the empty function would be removed completely during compilation?

That builds or doesn't an entire file. Assert works as a statement. There is not an equivalent in Go to conditionally removing just a statement in a function based on a compile time option.

Re: Why Is SQLite Coded In C

#288
post #273

Earlier quoted context omitted.

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.

Modern compilers like clang and GCC both have static analysis for some of this. Check out the undefined behavior sanitizer.

[deleted]

Re: Why Is SQLite Coded In C

#289
post #131

Earlier quoted context omitted.

Is SQLite looking for new developers? Will they ever need a large amount of developers like a mega-corp that needs to hire 100 React engineers?

No, but as morbid as this sounds, the three(?) devs one day will pass away so now what?

> No, but as morbid as this sounds, the three(?) devs...

Two full-time core devs and three part-time "peripheral" devs.

> ... one day will pass away ...

And not a one of us are young :/.

Re: Why Is SQLite Coded In C

#290
post #276

Earlier quoted context omitted.

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 recor…

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.

Sure if the only thing that matters is what happened in 1990, and nothing else that came afterwards.

Also if we ignore the historical tellings from Apple employees at the time, in places like the Folklore book and CHM interviews.

Post reply on HN