10 ms·
I've commented several times before that I consider "C" and "C with analysis backing" to be in practice two different languages. SQLite is the latter: https://s
by jerf 9y ago
I've commented several times before that I consider "C" and "C with analysis backing" to be in practice two different languages. SQLite is the latter: https://sqlite.org/testing.html https://sqlite.org/testing.html
Writing SQLite in "plain C" without all that would, well, simply not work.
I agree that "C with analysis backing" is the best language for SQLite right now. However, it should not be used as an example of "How C is a great language for programming in" unless you are also planning on skillfully using a very significant subset of the tools listed in that document. SQLite doesn't prove C is great; it demonstrates how much additional scaffolding is necessary to wrap around C to get that level of quality, and given the quantity and diversity of tools we are talking about, it is not particularly complimentary to "plain C".
- pcwalton 9y agoI agree. SQLite gets away with using C because it literally uses military-grade levels of verification. As John Regehr pointed out, SQLite is quite possibly the only piece of software that goes to that level of validation and testing without being required to by law. It's not just a matter of skill, either. The cost in terms of money and time needed to develop software in that way is completely impractical in almost any commercial scenario. Aside from some very specific situations, it's not an economically viable way to produce software.
- IloveHN84 9y agoIn Germany there are strict regulations if you're writing secure software, especially under the lens of BSI and of the Bundesdruckerei. Softwares which deal with eID are verified and certified with strict rules
- signa11 9y ago> In Germany there are strict regulations if you're writing secure software, especially under the lens of BSI and of the Bundesdruckerei. Softwares which deal with eID are verified and certified with strict rules just curious, does this extend to dependent libraries as well ?
- epse 9y agoYup
- zerr 9y agoRegarding the viability, another thing to consider is that C gives you an ubiquitous compatibility.
- bsenftner 9y agoit is not economically viable for entertainment or disposable "apps", but extremely required for any serious, mission critical software. Seriously, the comments here betray how many people are in disposable software careers.
- pcwalton 9y agoThe comments here betray how much of the software economy depends on developer productivity. The fact is that SQLite style verification is not practical for almost any software, very much including "mission-critical" software.
- jt2190 9y agoCan't it be both? We need it right now and we don't need to to work perfectly or last forever. Really, we're talking about the same thing like they're two separate things: The software [1] (in this case, SQLite) and the application (whatever tables, queries, etc. you need to solve your problem) are used together. So we build the poorly tested, quick and dirty application on top of the well tested, solid software. [1] Yes, I realize that "software" is a terribly generic term to use to mean "well designed and tested software" and that "application" is also a terribly generic term to use to mean "hastily designed and untested software". Feel free to mentally substitute your own terms if you have better ones.
- phaer 9y agoYes, but look how much of the software economy's infrastructure* depends on underfunded products. OpenSSH, GnuPG and OpenSSL are just 3 projects which are installed on pretty much every Linux server on the internet, including the servers of billion-dollar-businesses. It got a lot better in recent years, but still: Quite a few economically viable software companies just depend on free labor for mission-critical software product which take a lot of resources to become solid. And while we are at it: http://www.openbsdfoundation.org http://www.openbsdfoundation.org https://gnupg.org/donate/ https://gnupg.org/donate/ https://www.openssl.org/support/donations.html https://www.openssl.org/support/donations.html
- simias 9y ago
- crb002 9y agoSQLite is litteraly used by the military in their Android phones.
- sli 9y agoIt's literally used by every Android phone, military or not. It can be used in iOS apps, too.
- kderbe 9y agoThe Opus codec has an impressive amount of testing behind it as well: https://www.ietf.org/proceedings/82/slides/codec-4.pdf https://www.ietf.org/proceedings/82/slides/codec-4.pdf
- z3t4 9y agoMost/All these tests are done by machine. Debugging (in production) (while your service is down) costs much more then writing a bunch of tests. The more states your program can be in the more rigorous tests are needed.
- nialv7 9y agoSQLite went through thorough testing, not verification. These are two different things.
- adwn 9y ago> SQLite went through thorough testing, not verification. These are two different things. I think you're confusing the terms "formal verification" and "verification". Testing is a subset of verification, but not of formal verification.
- aidenn0 9y agoWow. Any one of the 3 test subsystems the describe is already ahead of well more than 99% of all software projects being developed. How is this funded?
- LusoTycoon 9y agohttps://www.sqlite.org/consortium.html https://www.sqlite.org/consortium.html https://www.cnet.com/news/adobe-funds-sqlite-database/ https://www.cnet.com/news/adobe-funds-sqlite-database/
- distances 9y ago> Consortium members can call any developer at any time, day or night, and expect to get their full and immediate attention I wonder how this works. For sure even the most dedicated developers will every now and then be on a holiday / concert / drunk.
- kzrdude 9y agoThis talk is really interesting too https://www.youtube.com/watch?v=Jib2AmRb_rk https://www.youtube.com/watch?v=Jib2AmRb_rk big industry projects (like the airline mentioned) probably contribute
- bsenftner 9y agoI disagree. Another comment here mentions "military grade verification" (?!) is required to write such high quality C applications. No, not at all, unless you count knowing what you're engineering as Military Grade Awareness. You seem to be saying you prefer the code-slinging style of "see if it works, it seems to work... release it". I've been including SQLite in various applications for 10 years, as well as have been coding, primarily in C, for 35 years. If you are not testing your work to a degree of statistical awareness of it's behavior, you're an irresponsible cowboy, hardly a true professional, and probably a liability to you and your team.
- TheDong 9y agoThe evidence is on the side of the parent poster. Incredibly experienced programmers write C without those tools, and with practically no exceptions memory issues, crashes, and vulnerabilities surface if the code is large enough and the project used enough. An easy example of this is the Linux kernel. They historically had relatively few verification tools and have one of the largest C codebases out there. There's a new vulnerability related to memory safety every two or three weeks. There's a bug fixed due to C memory management at least daily. None of those bugs would have happened in Rust. Most of them couldn't have happened in well written C++ (whereas this well-written C is chock full of them). Note as well that the kernel now gets some of the most exhaustive verification of any project (such as from google's syzkaller, etc), and it still has tons of C memory issues.
- bsenftner 9y ago"Incredibly experienced programmers" ? The language is simple and well defined to the degree one can map out exactly what happens on paper, if need be. Everyone is so brainwashed to think C is some low level assembly like language that is "hard". No, not at all. It simply provides no training wheels or safety harness - meaning one needs to know what they are doing, not coding in a "type and see what it does" style.
- TheDong 9y ago> It simply provides no training wheels or safety harness - meaning one needs to know what they are doing Meaning that if you are human you will make mistakes. My point is that people who do know what they're doing still make mistakes. Clearly the tool does not match the reality of human cognition.
- ksec 9y agoWow, I never knew SQLite was that well tested! I was recently looking at bedrockdb, and other DB built on top of it. Anyone knew what happen to UnQLite ? By the same author.
- jmull 9y agoI'm calling BS here. Look at the types tests listed in the executive summary... which of these can be obviated by language features? I'll try to break it down: * Out-of-memory tests: no, all languages run out of memory. The explicit nature of memory management in C might help here, since there's no mystery about exactly where the failure might occur. * I/O error tests: no, IO failures are independent of language. * Crash and power loss tests: no, this has nothing to do with language. * Fuzz tests: yes, partially. Different languages can reduce the range of invalid input a program could encounter. * Boundary value tests: yes, partially. * Disabled optimization tests: no, the optimizations being referred to here is a feature of SQLLite, which would need to be tested, regardless of language. * Regression tests: no, this is independent of language. * Malformed database tests: partially, because some languages are better at validating input statically, which covers some of the cases of malformed databases. * Extensive use of assert() and run-time checks: I say no. Yes, asserts are code you need to write, and a cognitive load. But navigating the built-in language constraints of more type- and value- validating languages are also a cognitive load. I believe asserts are often a lessor load since they can be in the problem space of the software being developed vs. the problem space of the language design. In C the molehill comes to the mountain. OK, Ok, on the other hand, in C no one forces you to write good asserts. But then, in no language does anyone force you to write code that actually does the job. * Valingrad analysis: yes * Undefined behavior checks: yes So, largely no. Other languages solve some problems, yet have their own drawbacks. You're drawing a sharp distinction between "C" and "C with analysis backing", yet there is no such distinction in the real world. We see in this project what we would see in every successful, long-running project (and do NOT see, 100%, in every project that failed in the long-run): controls in place to deal with the potential pitfalls. One advantage to C is that it's history can give you some nice guidelines to understand when you have pretty good coverage on those, from a language standpoint. I mean, I'm not arguing that some modern languages have their advantages. But, they have disadvantages as well. And, their advantages -- restricted as they are to static analysis -- solve little problems, not the bigs ones.
- jerf 9y agoI never claimed that language features can obviate all the things. I'm just saying that you can't use SQLite as proof that C is A-OK okey dokey it's OK to just keep programming in it forever, because it does not use C. If you're not putting in that much effort to your C codebase, then you're not getting those results. Also, while I'm sure you don't intend it this way, simply listing the issues like that is a bit visually deceptive in that our hindbrains tend to assume all those issues are roughly equally weighted, because they're all roughly equally the same size. But the distribution of issues there is very non-linear. C doesn't just have a bit of an issue with undefined behavior; it is nearly (but not quite) uniquely damaged by it. Hypothetically some type systems could partially cover some of the things you've labelled as "no", but I'll aggressively beat you to the punch that such things are very hypothetical, except I'll be saying it with sadness and through grinding teeth, because I find it frustrating how thoroughly our environments ignore some issues like that. But that's a rant for a century I don't expect to live to see.
- phamilton 9y ago> OOM tests are done in a loop. On the first iteration of the loop, the instrumented malloc is rigged to fail on the first allocation. Then some SQLite operation is carried out and checks are done to make sure SQLite handled the OOM error correctly. Then the time-to-failure counter on the instrumented malloc is increased by one and the test is repeated. The loop continues until the entire operation runs to completion without ever encountering a simulated OOM failure. Tests like this are run twice, once with the instrumented malloc set to fail only once, and again with the instrumented malloc set to fail continuously after the first failure. That's pretty awesome actually.