C++ web development framework

Abstract

C++ has always been considered a language for mission-critical server-side functionality. Web development, although in part server-side based, is done using different software development languages. I try to analyse what caused this situation. Possibility to provide a portable pure C++ web development framework is explored.

Target audience

This article is for people, who believe that C++ can be successfully used to build sophisticated web applications and are frustrated by the lack of basic tools to do so. It doesn't provide any kind of definite plan on how to create a C++ web development framework, but rather tries to share some thoughts, give an inspiration and some guidelines.

This article is also an invitation to dialogue – please share your thoughts and ideas, using the comments form below or my contact details page.

What this article is not?

To make things clear, this article definitely does not claim, that C++ is better than other software development languages, or that it should be used for every project, or that it doesn't have problems of its own. It rather tries to describe a niche set of requirements and applications, where using a C++ web development framework would make more sense, despite all the issues involved.

Current status

Available solutions

Today there are 3-4 most popular platforms to do server-side web development. These include:

  • Java and Java-based technologies, such as Servlets/JSP, Java Face, Struts and so on. The multitude of Java-based frameworks is a little bit dizzying

  • ASP (legacy) and ASP.NET, together with all Microsoft-related technologies (ADO.NET and other .NET libraries, legacy COM+ etc.)

  • PHP (for smaller sites)

  • Perl (CGI – legacy, mod_perl)

I don't want to describe in detail all these and other frameworks, available on the market. Just to mention, the last two entries are actually scripting languages and their performance is even worse than that of bytecode-compiled ones, like Java. In terms of functionality, all of them provide enough tools to create flexible and powerful web applications. They can and have been used to solve real life problems. However, in my opinion, for some extremely demanding sites they are simply aren't good enough.

There are a few frameworks, using C++, most notably Microsoft's ATL sever. They are either Windows-only or quite limited in their functionality or both. Their specifications have not been updated for years and most of them do not enjoy any vendor or community support.

Why C++ is not used?

One of the main reasons C++ is not actively used to do web development is the lack of standard tools and libraries. There is simply no feature rich library, which includes all the necessary boiler-plate code needed to write web applications.

The numbers of new C++ programmers, trained in universities and by the industry are falling, and some existing developers are converting to other more popular technologies.

Why a new framework?

C++ is an extremely advanced and flexible language. Its performance is still unmatched by other languages, popular today – likes of Java and C# (for an interesting point of view on why many benchmarks, claiming that Java is faster than C++ are not applicable to the real world look here). Even more important, it can be tightly integrated in most widespread web servers (Apache, IIS) to run in-process, and not as an external service, thus eliminating inter-process communication.

One of the main advantages of C++ is its tight management of resources, such as memory allocation. And indeed, although doing explicit memory handling properly can be a nightmare for an unexperienced developer, by using modern programming paradigms, it can be exploited to give a powerful and safe control over resource allocation and destruction. The predictable nature of C++ memory management, as opposed to concurrently run garbage collectors, is an important feature when squeezing every single flop from your CPU.

Also, using C++'s template system and rather sophisticated techniques, based on it, such as meta-programming, can help in creating sets of highly decoupled components, which can be assembled into complicated pieces of software easily.

Economics: isn't hardware cheaper than development time?

This is the question, usually asked by project managers and those, who pay the bill. The idea is – take whatever solution is available already on the market, and if it is a little bit too slow, throw in a bigger iron or two and your bottom line will still be better than if you wrote the staff from ground up yourself.

This is a perfectly legal argument and it is actually applicable to many real projects. Hardware, especially Intel-compatible is quite inexpensive, so throwing in an extra G of RAM or a faster hard disk is usually a matter of few hundreds of dollars.

However, when we start talking about doubling performance of a very busy web site, with a lot of heavy activity, things could look a little bit different.

For example, imagine you are running an extremely successful advertising campaign. As an outcome, your current farm of 30 2U IBM xSeries servers does not provide you the performance you want anymore, and you think that it needs at least doubling. Therefore, in the end you will have 60 servers. Let's ignore their acquisition cost for a minute (but it will be a hefty $60,000-$100,000 or more). What if you don't have enough floor space in your data center to accommodate them? Will you have to move to a new one, increasing your rent bill, incurring the cost of removals and suffering service disruption? What about extra system administrators you might need to hire in order to support them? There are other components in your system, which might require upgrade, databases for instance.

The conclusion is that doubling a large computer farm is not as simple as buying two servers instead of one. Therefore, for large and business-critical application it makes sense to consider investing into performance, even if it means using less popular technologies.

Potential adopters

I have already stated, that not every single web application should be written in C++. My intention is to give a powerful and flexible framework to those entities, which need to run extremely busy sites and which are prepared to invest in development of such sites a little bit more, knowing that the result will be much more powerful and scalable than any other alternative.

I consider high profile web sites, such as popular portals (Yahoo!, MySpace, AOL), blogging communities (LiveJournal, Blogger), relationship building (LinkedIn, OpenBC), popular on-line shops and others, receiving millions of visits regularly and delivering dynamic content to the users.

Naturally, I don't believe that all of them will ditch their current platforms and switch to the new toy of the month. But if a successful platform existed, over the time some of them would evaluate it and use it for some projects.

The following would be key factors, which could make a C++ web development framework attractive for potential users:

  • Highly dynamic site – large portions of the content cannot be cached effectively and need recreating on every view

  • Huge number of visits

  • Availability of necessary resources – developers, administrators and so on

  • Good project management procedures in place

How to succeed?

I don't believe in writing code without well defined and detailed plan. Not only software design and implementation are important in such a project, but also the whole management of the development process and proper PR are essential in order to achieve success.

Learning from other projects

It is important to learn from others and analyse their mistakes and achievements. A very interesting example of a successful major project is Subversion.

For years the only realistic option, available for version control in the open source world had been CVS. Although robust and well tested, it had a long list of shortcomings, which were never addressed by newer releases. A few attempts to build an alternative failed. Nonetheless, a few developers from CollabNet made an effort and created a hugely popular Subversion system. It fixes many problems in CVS, adds new features and provides a flexible and easy to use platform for extension and embedding.

One of distinctive features of the Subversion project is their superior documentation, good development plan and reliable release schedule. Also, they deploy an interesting business model, discussed later in the text.

Learning from other frameworks

From technology point of view we shouldn't ignore experience, gained by other frameworks. Many of them were created by listening to real world feedback from web developers, and learning which issues were raised and how they were resolved is important.

Of particular interest would be the J2EE and ASP.NET platforms since a lot of serious and complex applications are built on them and they were designed by dedicated and highly experienced teams.

External applications and libraries

Wherever possible, existing libraries and tools should be used. Examples include:

  • Apache/IIS – HTTP server platform

  • ICU – Unicode and locale library

  • Apache apr library – for platform-independent functionality, when not provided by boost or others (DB and other stuff)

  • Boost (threads, regular expressions, general C++)

  • log4cplus (or log4cxx from apache) – logging

  • Adobe open source – extra algorithms

Orthogonal components

The following components are essential pieces of any modern web development platform:

  • Integration into containing HTTP servers/application servers, such as Apache/IIS

  • Abstracted HTTP request/response framework – handles of different HTTP request types

  • Configurable session management – preferably using cookies. Session storage should be easily changeable (shared memory, file, DB etc.)

  • Configurable authentication (reuse server’s services)

  • Centralized resource configuration (database connectivity, start-up parameters, logging)

  • Simple template system – for clear separation between business logic and visual representation

  • Common DB layer (using existing libraries like arp), an ORM library, similar to Hibernate

Business models

When developing such a project, it is important to look at the whole picture. This includes the business approach, taken by the development team. There are basically two approaches, which can be considered.

Volunteer development

Development is done on voluntary basis – the code is open source, and people who find the project interesting join and contribute. This is a powerful approach, and a lot of popular projects have been developed this way or are being developed as you read this article. The problem, of course, is in keeping enough high quality developers and other professionals interested in the framework. Many good open source projects died because of lack of interest.

Sponsored

Under this topic I would file any form of development, done by salaried or otherwise paid developers. The result can be closed source or open source and in later case can even enjoy contributions from voluntary developers. However, there is always a dedicated core, willing to develop and support, for money if not out of love of writing software.

Subversion project is developed using this approach and is quite successful. Other major software packages include Sendmail, Fedora Linux distribution and many others. This model is quite flexible and allows some cost saving by using voluntary contributions, high popularity and trust due to the source being open and also income in form of money contributions, consulting services and paid-for support.

Project management

Whatever business model is eventually selected, I believe that there must be centralized leadership for the project, be it in form of core open source development team or management of the sponsoring company. Otherwise the project will never succeed due to never ending arguments.

Design needs to be clear and flexible, and there must be an organized development plan with release schedule. As much as possible and realistic, the code should be covered by automated tests. And no releases should be made without documentation, otherwise no one will know how to use the software.

Applications

It is important to provide applications together with the framework. Also, it would be very important to actually try the ideas, built into the platform in some real world code, so it would be nice to see some of the applications listed below, being created in parallel with or as part of the main development process.

Message board

A real-world example – should be extremely fast and robust. I would think about using Berkeley DB as the data storage, as opposed to a conventional relational database. This way the application would be really fast, especially if proper caching is built into it.

The data storage layer should be abstracted, so can be easily replaced.

Another nice feature would be single installation – multiple independent message boards, so one could provide hosting to different unrelated boards, all configurable and manageable independently.

Blog

Feature-rich and fast – the application should share a lot of code with Message board.

Web Mail

Feature-rich, similar to Gmail, Yahoo! beta e-mail system. Such application can be used to provide free or commercial web mail services for large communities.

Catalog / on-line shop

Taxonomy upgrade extras: 

87 Comments

Yes, I would definately get

Yes, I would definately get involved in developing what you are describing here, a C++ web development env with tools, because the system would run very very fast.

All the users could adopt the system and not necesarely just those interested in speed improvements over java/php/ruby/perl.

From my point of view as a web developer, any scripting language wouldn't make any sense I were able to do the same things in C++.

Waiting for a C++ WEB

Waiting for a C++ WEB development platform to happen on LINUX!

Windows ATL is awesome, wish we have an equivalent for opensource.

There are lots of powerful concepts in C++ which are unfortunately rotting away if we don't put into practice and keep doing projects in other languages.

Good initiative ! I applaud

Good initiative !

I applaud in creating web applications in C++. Especially for scientific applications this makes a lot of sense, or in any situation where some C++ library is already available for the business logic.

Perhaps you should also take advantage of the transformation that AJAX is causing in web application design. A clean plate for a web framework here is an opportunity, given that many successfull page-based frameworks (like PHP/JSP/etc... but also the fashionable Ruby-on-Rails) have the almost impossible task of putting AJAX support in their page oriented approach somewhere. In that respect, perhaps you should get some inspiration in some innovative projects like Wt (C++) or Echo2 (Java). Also consider that some of the most successfull and recent web applications (like GMail) are not using any of the existing frameworks at all, so there is clearly a lack of decent solutions !

Thanks for pointing me to Wt

Thanks for pointing me to Wt - it is quite an interesting project which goes into the right direction.

Yes, indeed, despite the large number of web frameworks, many of them have different drawbacks. But only big companies, such as Google, can afford creating a brand new framework in-house. For others the only option is to stick with the crowd. Here is where open source developers can come to rescue :-)

You forgot about the use

You forgot about the use case of having an embedded system with a web-based user interface. I work for a company who sells a piece of hardware that has 2 MB of compressed code space and 8 MB of RAM. We can't afford PHP, Perl, Java, etc. So, a C++ web application framework (that is not tied to Linux OR Windows) would be a great help.

C++ is my favorite language,

C++ is my favorite language, is fast, portable and he have a lot of nice tool for development. So at this time i work in aerospace sector and i develop a quality management system. I do it whit Jboss seam. The main idea is nice but when it come the time to write and debug the code, the nightmare just begin! each line is a new adventure. The problem is this one, J2EE is base on to many different source, JSF (myface ...), EJB3(glassfish, jboss AS), (seam, to made easy the link between the first tow framework i mention) and for a nice looking interface you can use (RichFace, IceFace, ajax4jsf...). If you need help there a lot of good book, each book have 500 pages, more or less. Why Ruby on Rail is so popular? It's because there's only one Rail!!! At my opinion if you wanna beat Java you have to follow the rail approach, I don't think you have to copy rail, like many project try to do, whit out success. At my opinion the requirement are that one,

- ORM tool in c++
- Ajax easy integration
- Crud generator, (And the generated code must be highly reusable! Not a what you see is all you get class!)
- Dynamic debugging tool, not message base html page, that very frustrating,
- Easy to configure, there annotation in Java, the pojo approach work pretty well. Since there is no annotation in c++ we need to rely on another approach. Ruby use syntactic signification rule. Another approach is to propose default value, so the user change value only when he need it... There a place for innovation here.

One tool you forget to mention is CORBA, one of the most powerful tool. CORBA is portable, fast, maybe a little bit complex but very powerful!! There anything needed for distributed application on it. The protocol IIOP is ten time faster one the network than any other text-based protocol like soap for example. CORBA is secure, there are encryption functionality build in it. All is needed is a way to write a simple client using a CORBA reference in JavaScript.

So if you need my help, i will very open to this project !-)

Hi Andre, I begin to read

Hi Andre,

I begin to read about JDO, Java Data Object. For a good WebFramework there a need for a good ORM, so the JDO specification give a nice architecture starting point. Java and C++ have alot of similarity. JDO use JDBC for RDMS i plan to use ODBC. The Oject type in java can be easly replace by Boost.any type. All is there to start the projet... What do you think about Cargo as a name??

Think about it

At first view, in JDO, i

At first view, in JDO, i don't see a lot of use of reflexion. But wen the type to pass to a function is unknown, the generic Object type is use. So the framework doesn't care about the type of the object. In counter part the client side have alway to know the true type of the Object and made explicit casting before use it. So the boost type Any is all we need here. For Hibernate, thats a well know ORM, he came before JDO specification and participate in many way of her elaboration. For performance issue take a look to this web cite, http://www.jpox.org/docs/performance.html (Jpox is an implementation of JDO). JDO was part of the J2EE specification, is in fact the persistence tier of EJB 3.0, if we plan to build a container style application like EJB (JBoss or GlassFish) that can be a good architecture to use. There not enough space here to describe in detail JDO but the most important question i try to answer is how i can made code enhancement in C++. Code enhancement is the way JDO works to made object persistent, that's is completely transparent to the application developer, To make long story short, an application from the JDO implementation, get the byte code an object and add persistence functionality. The application developer have to write a configuration file in xml that tell the JDO enhancer what class and field need to be persistent.
Another approach available to JDO implementors is enhance the source of the client application itself. The JDO implantation user write her class and a program written by the JDO implementor modify the source code of the class directly, (that's can be made in c++) but we lost transparency, in counter part the code is more verbose, easiest to debug. That's a sample of the consideration we have to look before made decision. A web framework implement the MVC pattern, so the model part the ORM is the first step to do. One of the powerful aspect of JDO is the abstraction of the underlying technologies storage. So it can be file system, ORDMS, RDBMS, or DB Berkley engine directly. I propose to take idea from successful framework and implement it in C++. On the way we probably find her way, that's agile!!!

The discussion is not over...
Another consideration is
Unit test
Bug tracker
Version control ...

Ruby on rails is a

Ruby on rails is a successful framework, and a reason for that is that it has tools that help you to develop fast. I like to much your ideas about make a web framework based on C++, also, I would like to help. It is necesary to make tools that let people to develop fast, not only to make a very fast framework. The proccess of development in the framework must be fast to be accepted by the people and we cant take ideas from the existing frameworks to do that. And example of that tools are the Ruby Standard Library, very diferent from the C++ Standard Library. I do not suggest to re-implement Ruby o something like that, but to implement the tools that support the framework and the other libraries. By the way, sorry for my english. I'm mexican.

Saludos.

I begin to write a c++

I begin to write a c++ Object Relational Mapper base on JDO architecture. I made use off c++ template meta programming for implement the heart of the system. Soon i am finish to write the base line of the system i will made it available on the web. At this time there's to much to do to have a good idea of the project. I use eXtreme programming approach for this project, agile method, and i am pretty proud of the results.

About base principle. Hi

About base principle.

Hi Andre,

I would like to put a couple of idea here about the architecture requirement. All the best web framework was build on Model View Controller pattern, and i pretty sure that's a good way to do it. One of the most benefit of the OOP, is the low coupling. In order to achieve that goal, we have to made a good design base on well defined parts, and we have to separate the interface from the implementation at the highest level as possible. Whit the MVC we have the three main part of the system, each part can follow the same principle, keep the interface at the highest abstraction level. For example, the Object Relational Mapper i design have for mission to give persistence to object. So ORM is one of the possible implementation of the design i do, we can have Object File Mapper, Object Embeddable Databases Mapper, and so on... The same client can chose the storage at run time, because the interface is the same for all implementation. For the View paradigm, we can reach the same level of abstraction, and at that level we can do event more, we can let the IDE do the job... A WYSIWYG modeler tool is needed!!!
The user can see exactly the result before running the result. If i go further in that way, the modeler tool can be a kind of gui compiler, the user can chose to generate HTML interface, or regular c++ interface, mobile device interface or what ever he need. HTML is the first goal here, but the design of the view module have to keep this level of abstraction. The last point i would like to talk about is the protocol independence. At this time http is the most use one for web frame work, but depending of the requirement the user have, the another protocol the system can use. So here again abstraction play a crucial goal. Protocol-independent framework is the way to go. In order to made it possible we can use the adapter pattern. The adapter is like a hardware driver, with this layer it become possible to connect new protocol when it need.

I hope thats can help a little, UML diagram can will be of better help.... Let me know your mail, we can do some design when you are ready.

I agree whit you Andre, it's

I agree whit you Andre, it's a lot of work. The visual part is not essential at begin, but we have to consider it at design time. All i wanna give in the last discution is couple of idea for the whole framework. Mabey the ORM i do at this time can give us a better idea of the application of this principles i explain in my last post.

Stumbled upon this post when

Stumbled upon this post when I started thinking about using C++ to create a web framework largely based on the principles of Rails. I've been doing Rails for almost a year and absolutely love the motivations behind Rails - MVC, Convention over Configuration, Plugins, Generators, etc. And I totally agreed that its the TOOLS behind a web framework that makes life easier for the developer..although the language plays a part too.

But this is a really interesting initiative and I'm looking to contribute if this gets more traction.

so i was looking to see if

so i was looking to see if there was a C++ based web framework and found this article. this is very wel written and a great read. i used to be a C++ developer and went over to PHP because it was less hassles. right now though i am planning to go back because of speed, power and performance.

you propose some great ideas. mostly that it was the tools and the specifications that made Java great for web programming. C++ would be immensly faster and it is what i would rather use. i am writing some documentation on writing my own C++WF but wanted to see other implimentations, writeups or white papers. very little is what i found and it is dumb founding once you realize how many OPEN SOURCE C++ libraries there are out there. putting them together as an ad hoc WF would work but a complete and concise WF would be best.

thank you for this write up. it was a great read and i thoughly enjoyed it.

-Taters

I've been working on a web

I've been working on a web framework in C++ for the past few months in my spare time. It's based on a lot of ideas from Django, but tries to migrate all repetitive coding into code generation. It uses a YAML configuration file to keep track of all the models (ie, tables in the database) and views.
There's no documentation yet, it's not done, and plenty of the code is ugly, but if you're interested in seeing something, you can look at the git repository: http://git.snoyman.com/cppweb.git. Let me know if you like it (or even if you don't).

I would kill to be able to

I would kill to be able to write a web application using only C++

I would love to help with this, but (without going into the boring and obvious details) my current employment prohibits this.

That being said, I've been thinking about the same things mentioned in the paper and I would like to offer a couple of thoughts:

1. Although I am a fan of the major frameworks mentioned under "learning from other frameworks", one thing I would change about ASP.NET would be a way to use much of the "base" functionality and ditch the page model in favor of a "more" template-based system. Essentially, I would like to get Apache to port Velocity to ASP.NET :)

2. Code-generation and/or reflection/introspection are going to be needed for things like ORM. I would also suggest that one or both will be needed for a "full" URL-based MVC framework. E.g. http://foo.com/bar/add?a1=100&b2=hello translates to something like (new bar())->add(100, "hello"). When you consider leveraging open source, you might want to look at Qt. Obviously, the GUI widgets would be completely ignored, and you would be introducing a compile step, but you would be getting introspection and some cross-platform help.

Just my .02 - which isn't worth much with the current exchange rates :)

Unfortunately, you are going

Unfortunately, you are going to fail.

Why? Because the developers you tap will come from desktop UI programming. They first thing they are going to do is develop a set of widgets, a widget hierarchy, and attempt to make the entire project C++ only, with no XML, HTML or JavaScript.

You're going to be so busy working on abstracting these concepts, that you're always going to be behind the people who are actually developing these concepts using Ruby, PHP and Perl.

Java, no, Javans have the same problem. Wicket is this up and coming framework for Java who's stated goal is to solve the problem of statelessness, as if this was 1996 and statelessness was still considered a problem. By trying to hide statelessness, the developers of the framework are unable to use design patterns that design for the stateless experience of the web. I want to carefully maintain state on the server side.

As a developer, I want to be aware of the fact that a visitor left with a full shopping cart after his credit card number was incorrect. Maybe he went to find his reading glasses. Maybe he left them at his office. Maybe he forgets about my website until a month later. I still want him to pick up where he left off.

Treating HTML, XML, JavaScript as a problem to be solved has already been posited in this thread, which takes it even further than the statelessness. This potpourri of different languages is the enabling technology of the contemporary Internet. Why would you want to shield yourself from it? Why would you want to express JavaScript in C++? I'm sure you could try, and come up with some marble-mouthed, inflexible frameworky class library, that renders web interfaces like a mittened four-year old with a box of crayons.

If you do build this, give C++ the job where it can excel. Create an action framework. Create a class to respond to a particular RESTful action and generate a streaming result. Use a templating language to generate your HTML and XML, but write out these templates in their own language, HTML or XML. Look at Java's Stripes for an example of a Java framework that knows it's place and does what it does extremely well.

I'd happily use a C++ framework, if someone would develop one that didn't require that I write HTML in C++.

I'd be interested in

I'd be interested in developing this, though I have other priorities (mainly school), which limits my time severely. However, I'd be available to do code review, for example, or other isolated tasks.

Is there a development page or wiki set up for this project?

i'm on the same wavelength

i'm on the same wavelength as what is being described here. what comes to mind is Qt, since it is a robust C++ framework designed to be portable to all the major OS', along with embedded environments as well. in my view, this page describes Qt for the browser (and server). not so much literally, but conceptually. such a framework should allow widgets to be drawn, an event model to trigger actions, database support, threading, ... most importantly, it could reuse existing c++ libraries, be type-safe, be portable and run close to the metal (in-process, if desired).

Pages

Add new comment

Filtered HTML anonymous

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
Are you really a mortal human being?
Image CAPTCHA
Enter the characters shown in the image.
Subscribe to Comments for "C++ web development framework"