Coding Websites in C++
Friday, April 13, 2012
I'm trying to make more 20% time for myself to experiment with things that are scratching away in my head. So I decided to have a look into something I've been thinking about for a while. Why don't we code websites in C++.
It isn't a totally new idea. Google is coded in c++. A lot of Yahoo is or was. And it was actually incredibly easy to make a module for IIS7 that did it. Here's a post I made in the programming forum with an explanation - and a bare bones project.
- More control. You can hold stuff in memory until the next request. Pool database connnections. There's a lot of application specific optimizations you can do in this way.
- Obviously faster than scripting languages like PHP
- If you code it right you can still use PHP etc.
- More to control. Threading. Multiple server instances. These could be seen as positives too though.
- Any speed increase will probably be paled into insignificance if you're accessing a database (but again - you have more options to detour around these issues).
- Probably not that much faster than something compiled like C#
I did get a nice system done. It has hotloading DLLs, so you could compile and refresh the page and it would automatically reload the DLL. It has virtual pages - so you can add a page string like "/my/page.html", or "/my/page.*" and it'll load the page from the specified class based on the request.
Ultimately I decided to stop working on it because I'm not totally convinced of the speed benefits (the database being the bottleneck). And while I do love C++ - I feel that coding websites in it would be cumbersome without spending some significant time coding a framework.
So here's some useful links for anyone else thinking of doing this.
- CTemplate - template system for c++ by Google (like smarty for php)
- Poco - looks like a good generic library with some useful stuff for anyone thinking of doing this.
- G-WAN - makes the case for webpages coded in c++. Unix only. (maybe tellingly, the website is down right now)
- Stack Overflow - there's a few threads on SO on the issue. Most make the point that we use PHP etc because it's established and it's easier. A good point is that things like PHP, ASP.NET, ROR and Java have had lots of money invested in them to evolve them to where they are today - but C++ doesn't really have anyone fighting its corner like that.
I get the feeling that there's undiscovered potential in there somewhere, so I still have it rattling around in my head.