What I did this summer
Inspired by Django, I've written an MVC web framework in C.
What the hell?
It's serving up this blog. It's a pretty responsive site, yes?
Features
- CGI
- Templating engine supporting inheritance (unlimited levels), template includes, iterative templates, and chained formatter functions
- Templates are initialized structs in a .c file
- User views, implemented as a node tree with a few basic data types
- Pretty URLs, parsed in a friendly way for matching to a view
- Site configuration is
#definedin a header - Will be released as GPL
Benefits
- A native-code CGI is easy to deploy
- Tiny surface area means higher security and fewer bugs (I'll defend this shortly)
- Very green (low resources, high throughput)
- Very fast
Minimal surface area for bugs and attacks
How is the framework "minimal surface area"? Everything is hard-coded at compile time. The trend in recent years has been to move configuration, templates, and data out of the framework code. Everytime an item is moved out of the binary, type safety is lost, which invites all kinds of bugs. The parsing of a configuration file represents more than overhead, it also means all kinds of user errors won't be detected until runtime.
Don't read this as a claim that the code is bug-free. But with a code-base this small, bugs are not hard to locate and fix.
To-dos
- Unicode support - stop snickering, I know what needs to happen here and it won't take too much effort.
- Template-block-level caching. This will be high-effort, but I can't defend a high-performance claim if a tag cloud has to be re-calculated with every request.
Might-dos
A data access layer. Currently the site runs without a database and I'm okay with that. I can easily add an interface to DBI when I need it. Or maybe I won't.Won't-dos
- ORN. An ORM is a time-saver at the start of a project, but an impediment later. What happens when your app upgrade requires a column be split into two columns? Maintaining data integrity here requires more care and feeding than an ORM will afford you.
- Run-time template parsing. Explained earlier.
Confession
Part of the Django inspiration is that I don't think the dynamic-languages crowd has any kind of exclusive lease on elegant design, and I'm a little tired of this pretense by some (not all) of the members of these (Python, Ruby) communities.Stay tuned
There will be a source release when I've got a few more features working like I want them. I hope a small niche of users will enjoy using this.