10 ms·
We could argue that modern static analysis tools and the compiler itself are good at catching a lot of errors, and that high level languages have bugs too. C is
by kuon 8y ago
We could argue that modern static analysis tools and the compiler itself are good at catching a lot of errors, and that high level languages have bugs too. C is a dangerous beast, but with good practices it isn't that dangerous. Of course you have to be extra careful when dealing with user content, like JSON payload, but many decoders in other languages are written in C.
Rust is a good solution, but it isn't trivial to learn, and might not suite all situations. I think it's great to have a C solution like this.
- zeth___ 8y agoWhen your messaging protocol is Turing complete you have no hope of a secure web server.
- peterkelly 8y agoJSON is not Turing complete
- gaius 8y agoC is a dangerous beast, but with good practices it isn't that dangerous. Of course you have to be extra careful when dealing with user content, like JSON payload, but many decoders in other languages are written in C. It isn't hard to build tools like Valgrind and AFL into your C workflow. I would take that over simply taking for granted that a higher-level language was secure just because it is interpreted. After all it's probably C under the hood anyway.
- marmaduke 8y agoThis is a good point: you can CI run tests under Valgrind with various sanitizers and -Wall -Wextra. In a small codebase with a few cores, one can compile and run a test suite faster than it takes for a Django app to start.
- unrealhoang 8y agoI don’t think any non-gc language is trivial to learn, C also. Manual memory management is hard, and either you learn from the system (C way) or learn it upfront from the language (Rust way), it’s still the same amount of concept you have to digest to write practical software.
- tannhaeuser 8y agoThat's true, but the original idea of Unix is to have many small program invocations work together, not to erect a monolithical long running daemon that does it all in a single address space. Memory management for one-shot command line apps isn't hard at all and can often get away with static allocations. Even if you're screwing up your heap, process isolation will take care of recycling memory when your program terminates.
- dannypgh 8y agoEh, that's the original idea of the Unix shell, sure. But Unix has many ideas. Long running daemons have been a part of Unix systems since the beginning.
- tannhaeuser 8y agoBSD 4.3 introduced inetd along with TCP/IP to mainstream Unix. Quoting from [1]: > When a TCP packet or UDP packet arrives with a particular destination port number, inetd launches the appropriate server program to handle the connection. For services that are not expected to run with high loads, this method uses memory more efficiently, since the specific servers run only when needed. Furthermore, no network code is required in the service-specific programs, as inetd hooks the sockets directly to stdin, stdout and stderr of the spawned process. [1]: https://en.wikipedia.org/wiki/Inetd https://en.wikipedia.org/wiki/Inetd
- dannypgh 8y agoI'm familiar with inetd, but I don't understand your point. Unix is more than a dozen years older than 4.3BSD. Claiming that long lived daemons is somehow anti-Unix is absurd. Just ask init or getty.
- j1elo 8y agoRust is a good solution, but it isn't trivial to learn Maybe another opportunity to mention Zig again as a possible good alternative in the learning curve front? (I learned about it when it appeared recently in the HN front page)
- earenndil 8y agoZig doesn't have any web frameworks yet, though.
- chx 8y ago> like JSON payload, Let SQLite deal with it! The JSON1 extension is quite capable of parsing, extracting, sorting and filtering JSON data and by default it's enabled.
- dijit 8y agoWhat is sqlite written in?
- nitrogen 8y agoSQLite is so extensively tested and widely used it may as well be written in stone. It doesn't count as "writing C".
- peatmoss 8y agoI think the parent is being a little tongue-in-cheek, but it’s a valid point. C is a dangerously inappropriate language to use... except when it isn’t. C still has some unique portability characteristics that are very hard to match in other languages. If your requirements lead you down this path, it can be done. You rightly point out however that this isn’t a path one travels lightly. Maybe the flip side of all this is, “if you’re prepared to invest the kind of rigor into testing that SQLite has, then rock on.”
- dangerbird2 8y agoYeah, if you run into a security vulnerability caused by SQLite, tens of thousands of websites, desktop apps, and virtually every iOS and Android app will be in the exect same boat.
- yellowapple 8y agoOr OpenBSD, for that matter.
- mbaeten 8y ago> Rust is a good solution, but it isn't trivial to learn, and might not suite all situations. I think it's great to have a C solution like this. Isn't the learning curve of C pretty similar or even higher than rust's if you concider all the best practices you'll have to learn and understand and use? Imho in that regard rust pays off very well (and fast), because it's compiler _enforces_ most of these "best practices" to everyone.