Sunday, 2 September 2007

servlets in C++ or 2 small C++ ideas

As I was recently reading the article of Stefan Wörthmüller "C++ Versus JEE"*. Basically Stefan argues that:

"If you want to write a server application, you need control. Maybe even control about your failures. But you need control."
And that of course is what C++ will give you. For the details refer to the article. However another sentence got stuck in my mind:
"I still wonder why there are so few approaches for Web frameworks/toolkits or application servers written in C++. C++ is made for such a task."
So I've got that big ;-) idea: why shouldn't I take the Servlet specification, restate the interfaces in C++ and code the Servlet classes and (perhaps) a servlet container! Why not use the language which is known to me (and many other server-side programmers) and combine it with an iterface which is known to many web-developers (i.e. Java programmers) to get the best of the two worlds? This will be a big success!!! Ok, I tell you why: no spare time.

But I still think this idea is not bad. It goes in the same vein as my other idea about C++: why should I use scripting languages for scripting? I can do everything just as well in C++. Ok, not everything, I would have to write some template libraries to plug the holes, but in principle I could. I didn't pursue this idea very long, but after some time I found the same reasoning explained more lucidly in the rationale of Boost's "Filesystem" library:
"The motivation for the library is the need to perform portable script-like operations from within C++ programs. The intent is not to compete with Python, Perl, or shell languages, but rather to provide portable filesystem operations when C++ is already the language of choice."
Then there is the Boost::String library which makes possible the Perl-like manipulations of strings... We are almost there.

But end of digression! The main theme of this entry are C++ servlets! So back to the web programming.

For some time I tried to find some C++ web frameworks by googling, but nothing useful emerged. So I a sort of gave up. Till today. I was googling for documentation of the OSE RTOS by Enea when I stumbled upon the OSE library. OSE, whassat? Never heard of it! Another legacy do-it-all framework? It turned out that this library was long time popular in Australia, and more: it has a HTTP Servlet support! At last!! It supports HTTP Session objects, XML, and its HTTP Daemon class seems to be a sort of servlet container. From what I've seen, its interface is different form Java's HTTPServlet class, but it is a start! Maybe one could combine it with a non-JSF view technology (Velocity?) to enhance it further? So maybe I will be able to pursue my idea nonetheless? But is it worth the candle? I would be only a copy of an existing technonogy, certainly not an "killer app" and not a new approach. Or maybe not?

* Dr. Dobb's Journal Jun 21, 2007,


Unknown said...

Unknown said...

Hello, I found myself doing the same questions, I mean why not?, C++ can be even faster than Java, and it is widespread so I definitely agree.

Maybe we could start an OpenSource project on this, let me know.


Unknown said...

it looks like there's already one


Anonymous said...

Well, plain C is not bad either:

TrustLeap G-WAN is a Web application server with ANSI C scripts (that are 5 times faster than ASP.Net C#):

G-WAN is up to 38 times faster than Apache, and probably 10x faster than the CPP server:

Anonymous said...

отличный сайт!

Marek Krj said...

Благодарю, очень мило :)

Anonymous said...

I think it's good to think in a different way than servelt, it is existing technology, to get industry acceptance, you need to do something more than servlet, cgi and in a different way. servlet's runs on slow VMs, response time is too slow & scalability has limits. we need to address it in a manner to solve this:

and run as native apps.

Stefan Frings said...

Maybe my project is what you had been searching for:

It's a web server library, it's interface is similar to Servlets and it also contains a template engine. But you may also use ClearSilver if you want a full-featured template Engine like Velocity.