I generally receive a stunned look when I tell people that we build everything with C++ where possible, including web applications. It happened again recently and they will usually ask me – Why?!!!

I’d like to document some reasons why we chose to use C++ to build web applications here. I shall preface by saying that we will use whatever language that the client specifies for client projects. However, for our own internal projects we prefer C++ over everything else.

Alright, now that that’s clear – why did we choose C++ as our main language for web development?

It’s clearly good practice to develop web applications using some sort of framework instead of writing raw HTML, CSS and Javascript. That’s how everyone is doing it and we are no different. So, the issue is which framework to use.

It turns out that there are a number of C++ web application frameworks out there. While they may not be as popular as say RoRails, Django or CakePHP, they are still very usable for web development. The one that we have been using for a while now, is Witty and it is available as an official package in both Debian and Ubuntu Linux.

It is a component/widget based framework for web application development that supports ORM based database abstraction for all the popular databases. It also comes a modular authentication framework including support for OAuth in the library. We write our code in C++ and the framework generates the necessary HTML, CSS and Javascript magically.

Since there are mature C++ frameworks available for web development, then there is no major stumbling block to writing web applications with C++. So, there is nothing wrong with using C++ for web development. So, the issue is why choose C++ over say Ruby, Python, Java, etc.

The answer is a rather pragmatic one – we mainly hire engineers. Unlike most computer science majors, most engineers learn C/C++ in school instead of Java or Python. Therefore, we’ve already developed some familiarity and experience with the language through 4 years of engineering school.

So, instead of subjecting everyone here to learn both a new framework and a new language, we’ve chosen to have everyone just spend their time learning a new framework and way of doing things instead. This saves everyone some trauma and they can get started contributing to the projects as soon as possible.

I would also like to add that while it may be simple enough to learn a new language within 24 hours, it takes a lot longer to get familiar with all the details of the language. Lack of familiarity is often the cause of poorly written code as the programmer does not know the drawbacks of the language and how to do things the correct way in any particular language.

Since we’ve been doing C++ web development for some time, we’ve also discovered some other pros and cons of doing so.

The biggest pro is the availability of libraries. If you wish to develop a powerful application you need to bank on the availability of third party libraries. In this respect, it turns out that there are a large number of available third party libraries, more so than most people think. Almost every major application provides some C/C++ library bindings – think OpenSSL, RDBMSes, etc. In fact, most popular web development languages actually interface to the very same C/C++ libraries.

In addition, we are also able to interface to random third-party libraries that do not provide bindings to other languages other than C/C++. While it is possible to interface to these pure C/C++ libraries from other languages e.g. using JNI in Java, the programmer needs to jump to extra hoops to get it to work – often through a translation layer to map calling conventions. We don’t.

Therefore, there are some interesting applications that can be easily built with C/C++ but become more cumbersome to do so with any other language. Of course, it all depends on what application you’re trying to build, YMMV.

However, the biggest con is also the lack of libraries – particularly for web services. Since C++ is not a popular choice for web development, it lacks the love and attention that the other languages have received when it comes to libraries for interacting with popular web services.

For example, if we wanted to interface with DropBox, we would have to fall-back to using the standard HTTP interface, probably via libCURL/CurlPP, to interact with DropBox as they provide official library support for languages other than C++ only.

This lack of love also extends to community support. Since the community is small, it is not as easy to find the solution to our problems on Stackoverflow. Therefore, we will have to actually understand and build the solutions ourselves. While a little more tedious, this is a great learning process.

As a final word – I would just like to point out one last reason to using C++ for web application development – it compiles to native code, natively. Of course, many will argue that the JIT compilers used on these modern interpreted languages are pretty awesome – and they are. However, as awesome as they may be, they can only hope to match the performance of well-written native code, not beat it.

That said, we are now exploring the possibility of writing our web back-end in C++ and using a JS framework for the UI such as Angular or ReactJS. That might turn out to be the best combination in the end.

To summarise:

Pros: No need to learn a new language; Massive availability of libraries; Performance.

Cons: Lack of available libraries; Lack of community support.