Main menu

[andre bar'yudin]

You are here

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.

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.

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 - 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 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.

Thanks for your comment. I must tell you, that I don't see embedded systems as my primary platform. Although I wouldn't mind deploying my hypothetical C++ web development platform in embedded environments, my main target are actually large servers for very busy web sites. In order to satisfy popular development needs and to provide a useful alternative to other frameworks, mine needs to include quite a lot of stuff, and might become relatively large, probably too large to be deployed in 2M.

That said, if the framework is kept "modular enough" it might be possible to compile/deploy only the necessary subsets of it, making it quite useful in the scenarios you describe.

Thanks for the link. From a very brief look at it, the framework seems to be a "C++-based JSP" (or PHP, or ASP). While JSP-like approach, I would be ideally interested in greater separation between logic and presentation.

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.

I am well familiar with web development in Java, and this is one of the things which led me to write the paper. I agree with you on most of the topics in general. What's important is that a good and detailed discussion is essential.

In the end of the day I don't want even start top level design before I have a team of at least 2-3 people in addition to myself, otherwise there is no future for the project.

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??

Any name would be fine. I don't remember enough about JDO (but other Java-based ORM systems come into mind, such as Hibernate) in order to make any conclusions about creating a similar C++ framework. Java and C++ are similar in many ways, but they are different in many as well. One particular thing lacking in C++ is reflection, and I wouldn't be surprised if a considerable bit of JDO's functionality depended on it...

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 ...

Dave, bytecode manipulation is a popular technique in Java, but it is not available in C++. So I don't know how we can make transparent persistence, using the language. Probably we will have to do some sort of hand-mapping, either in code of the object or some external mapping.

An option to consider is Aspect Programming for C++ - see http://www.aspectc.org/ for instance. The problem is that it introduces an external tool dependency for the developers, which is always not very good...

Sounds like an interesting idea, especially the "templates". Need more reviewing in order to understand whether the thing does everything I want.

One major problem is that the project is closed source. I am not a zealot of Open Source in general, but I believe that otherwise such system has no chance of getting sufficient market share and therefore has no future.

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.

I cannot agree with you more regarding the solid foundations required for the success of the framework. It should be relatively easy to do the required basic stuff, so that the developers can concentrate on business logic implementation and not on the boiler plate code, required by the toolkit. And this is the reason I think it's quite a complicated task in the first place.

Recently I can see more and more people who are to contribute. If I have more spare time, I will start writing some design documents and eventually something might come to life.

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.

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.

David, it is all sound and good. Many popular frameworks are based on the same principles and it makes sense to reuse them. But it is a lot of work, obviously. Especially the visual design part. Anyway, discussion is necessary. My e-mail is in the contact section (bottom of every page), feel free to write.

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 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 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.

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 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 :)

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++.

While you have a valid point, trying to explain, why previous attempts to create a C++-based framework failed, I think you are making wrong conclusions from my article. I definitely don't want to eliminate HTML/JavaScript/CSS from the development lifecycle. The framework should not dictate a single approach to the creation of the web GUI, therefore a variety of paradigms is possible.

One could be indeed a rather rigid C++ only hierarchy of widgets, which would generate some simple tight HTML, probably not giving you much options in creating pretty looking AJAX interfaces etc., but which will abstract all the weirdness of modern web development from an uninterested programmer. Such set of widgets might be extremely useful in, say, embedded world - when you want to create a simple GUI for your router or other device, where nothing fancy is required, but memory/CPU constraints are tight.

Another library on top of the framework could be much more flexible, doing something along latest versions of JSP tags (or whatever they are called).

Yet another one could follow Google's approach of compiling Java into HTML/JavaScript.

All in all, I don't see my framework as an all-purpose one, it fits more in different niches, such as either exceptionally high loads or constrained hardware.

Andrew, at the moment there is no active development going on, related to the project. I'm interested in gathering opinions from a wide range of developers, as well as observing the current state of the web development frameworks.

I won't start any development until I have a solid core team of at least 3-4 high-level C++ programmers with considerable Web experience, otherwise the project is doomed from the start. Any extra part-time involvement is, obviously, more than welcome.

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).