6 ms·
C with libdispatch and clang blocks is the most fun I’ve had programming in quite some time! Here’s a web framework (complete with ORM) modeled on ExpressJS wr
by williamcotton 4y ago
C with libdispatch and clang blocks is the most fun I’ve had programming in quite some time!
Here’s a web framework (complete with ORM) modeled on ExpressJS written in C:
https://github.com/williamcotton/express-c https://github.com/williamcotton/express-c
The finished product is < 90Mb Docker image that idles at like 2Mb of memory.
There’s also a lot of examples of the (basically required) support tooling like Valgrind, AdSan, etc.
Check it out!
- winrid 4y agoIt looks cool. The DB library is appreciated. However, you would get about the same idle memory and docker size with Go's Fibers framework :)
- williamcotton 4y agoLol, yeah, the libdispatch runtime is probably about as big as the Go runtime! I think this has a slight advantage in that it uses a memory arena for a per-request bump allocator so it should keep overall memory usage lower. The slowest part of all this has to do with Block_copy and the places where I’m very much treating blocks/closures in an OOP type manner. This could be fixed by writing a different function that did basically the same thing as Block_copy but for all the “methods” on an “object” in a single pass. But who has time for that? :D Here’s more about those performance issues and some example code that show how slow the approach is: https://github.com/williamcotton/express-c/tree/master/research/blocks https://github.com/williamcotton/express-c/tree/master/resea...
- preseinger 4y agogo-fiber is a weird, non-idiomatic, and non-serious project, fine for a proof of concept, but definitely not something anyone should be using in prod but your point is sound, any reasonable go http server will have the same level of memory usage at idle
- winrid 4y agoWow, really? The project has 25k github stars and 300 contributors. They are on v2.44. Why is it not serious? What makes any software "serious" to you?
- matheusmoreira 4y agoCarmack said low level programming is good for the soul, he's right. C is a fun programming language, don't even know why. Freestanding C with no standard library is the most fun I've had programming ever. I'd like to share my project as well: a Lisp interpreter written in freestanding C. https://github.com/lone-lang/lone https://github.com/lone-lang/lone
- williamcotton 4y agoOoh, I really like this and from a cursory glance it looks very legible, I’m definitely going to poke around later!
- int_19h 4y agoI would argue that Forth is really the perfect thing for such zen-like pursuits, building it up from scratch bit by bit. Freestanding, especially on some more exotic platform, is more fun, of course.
- preseinger 4y agothis project makes assumptions about received input (specifically encoding) which aren't guaranteed fine for a toy project, not something that can be used in anger
- williamcotton 4y agoAre you referring to the req->sendf as seen in the README? Yeah, I definitely wouldn’t use that approach for user input! There’s also support for mustache templates and JSON-API endpoints as well. Or are you referring to something else? But yes, please don’t use this for anything serious!