I've inherited a pretty interesting project where there is a good opportunity to take an existing piece of software and turn it into a SaaS web app. As the project is inherited, the code base/ framework is already defined as C++ and MySQL. The app itself is compiled and run as an EXE on Windows Server. The UI is web based and the app works as a kind of server. From what I do know of modern web apps, this is perhaps an unusual choice. These days, most people seem to opt for a PHP framework or Ruby on Rails. Certainly that is the impression I get from reading blogs on the subject. So, I'm very interested to know if a C++ EXE backed by MySQL is a solid foundation for a web app, or whether we should be looking to build in another way?
It is OK to make a web application using C++ IF the benefits outweighs the cost, obviously. Google, Amazon, Facebook are all built with C++ for efficiency in speed, memory and energy - aka servers costs.
However as you guessed, there are drawbacks to using C++ for this. It depends on your tools though.
When CppCMS Should Be Used.
C++ language is far from being popular for Web development for many reasons: lack of appropriate tools, skills of developers and many more.
However, there are areas where C++ web programming with CppCMS becomes very useful and efficient, and some where it is just a waste of time.
When CppCMS should or can be used?
1.High load web sites and application with hundreds and thousands hits per second, where high performance, efficiency and scalability is required.
2.Application that require scalable Comet/Server Push technologies --- CppCMS can efficiently handle hundreds and thousands simultaneous HTTP connection with minimal resources usage.
3.Embedding web interface into existing C++ applications/services with a small cost of additional library.
4.Embedded underpowered devices -- CppCMS allows creation of rich applications with relatively low cost of hardware that would perform reasonably fast.
When Not To Use?
If you create small web applications that do not require high loads and require very short time-to-market period -- probably tools like Django or RoR would be more appropriate for such tasks.
The drawbacks specific to C++ are:
- Compile times can be very very very very slow compared to other languages. This might impact iterations, release interval but also developer's moral. Make sure it's worth it.
- Most of the time, you need to compile changes. It can be avoided but it's the usual.
- Writing modern C++ makes it easy (to learn, read, write, debug, etc.), but a lot of C++ developers don't know what is Modern C++. So if you work in team, you need to have good knowledge of Modern C++ from the whole team. If not, you will easily get into very complicated bugs. That said, it's more a people problem than a language problem. It's just that C++ history didn't help make it easy to grasp. Good teaching is not as common as in more modern (historically) languages.
- Unicode is still poorly supported by the core C++ language, making it a potential source of great pain. Just use UTF-8 everywhere and some libraries (look into boost) to manage it.
- C++ standard don't know what is a library. So we use conventional ways to manage them on different compiler/linker/OS. This might be a problem if you start to get into cross-platform code that need to load/unload "on the fly" some modules.
Maybe take a look at CPPCMS? Or maybe wt if you want to make a GUI-style website?
Also check these questions:
Wordpress running in PHP with a few plugins installed brings my Winders server to it's knees. So I have no problems at all with the idea of implementing a web application in C++. Speed is a critical part of the web experience.
Graphic design tents to drive the majority of web projects. PHP is an obscure scripting language that runs inside HTML. Allowing the PHP authors to escape in and out of HTML. There are many benefits with working with HTML as a result.
Still, you could implement any number of HTML template solutions in C++.
One could provide you with an long list of Python and PHP frameworks that make for rapid development, but if you have lots of time then C++ is definitely possible.
What I don't understand is your decision to do C++ on Windows. lol
It certainly is an unusual choice. C++ wasn't designed with web applications in mind, and while libraries exist to write, say, FastCGI applications with C++, you have to do a lot more work to get your basic application up. "Web languages" usually do a lot of things for you that you have to get from elsewhere in C++, such as implementing the HTTP protocol, generating HTML, etc.
Also, web applications are mostly about strings, which isn't exactly C++'s strongest side - there is no string type built into the language itself, and this leads to a few quirks and makes string processing more clumsy than it would be in more high-level languages. Handling character encodings correctly in C++ borders on black magic. And C++ can crash really hard, on fairly innocent-looking code, which is far less likely with a higher-level language (they too can crash, but in most cases, the web server can recover gracefully, especially on platforms that use a per-request lifecycle model, like PHP).
That said, if you have most of the codebase written already, C++ might still be a viable choice. You will need to find some libraries to cover all sorts of web things (most notably, you want to be able to either integrate a standalone HTTP web server into your program, or hook into, say, Apache, either through FastCGI or by compiling to a module; you will also want some kind of templating library to make rendering HTML documents painless).
Finally, there's the developer market issue. There are plenty of C++ developers available, and even more web developers, but the overlap is probably not that large, so if you ever need to hire people to work on this thing, you'll have a somewhat harder time than with, say, PHP.
As others have said, conceptually, C++ is a fine environment for a web server development. There are however, several considerations as you make that decision.
The popularity of scripting languages for web server design is turn around time. Simple changes can be made easily with the demonstration of results nearly immediate. You will find that any good web server design will offer similar capabilities. Indeed, C++ is an excellent environment for achieving that goal.
The key to building a good web server application system is a separation of UI from code. A goal in building a web application environment is to avoid "Your UI is in my code and your code is in my UI."
I would like carefully at systems like cppcms. I would expect that it offers something similar.
You don't need a scripting language to offer flexibility and performance.