views:

4218

answers:

21

I don't know why this is question is bugging me, but time after time I come back to the though - why not make websites in C++? So far I know of none (except a rumor about Yahoo). Most use PHP, Java or ASP.NET. Some are built on Ruby or Python, but even those are minorities.

At the same time, looking at StackOverflow, it seems that C++ is still a very popular language with many projects written in it. Why not for webpages?

So - what do you know about this subject? Are there any websites written in C++? Are there any framewroks/libraries that help doing this? Have YOU ever done it? If yes, did you run into any fundamental problems and would you recommend this to others?

+1  A: 

Frankly, there are better languages to use in relation to web application development. Some are based on C/C++ (PHP comes to mind) but basically they are an abstraction above C/C++.

There isn't anything stopping you from using C++ in a CGI environment, but it's a lot more difficult. It would be much easier to use a language that has the features needed for web application development built in (such as session/cookie handling and request/response generation).

With that being said, I have written a C based application to interact with a third party database that supported a PHP based web application. They had APIs in PHP and C, but the PHP API was entirely way to slow so I wrote a C application that was called by the PHP.

scheibk
+3  A: 

We used it at my last job almost exclusively. It worked well, though we used our own home-grown web page engine (like ASP or PHP, but our own concoction), which I probably wouldn't use in the future for a variety of reasons. Those sites are live around the world, and there's a good chance you've used one before (I can't give many more details due to NDA).

To answer your question, though, C++ is an excellent all-purpose language, and that includes the creation of a webserver. In order to create dynamic content, you might have to do some gruntwork, but I wouldn't be surprised if there are existing C++ web app frameworks out there for you to use.

Brian
+1  A: 

I would be surprised if C++ is used in any new website builds. I used to use it for making COM components for MTS back in the days of when vanilla ASP and transaction server were the way to do things, but there are much more efficient languages and frameworks to lean on now that make development much quicker.

Steven Robbins
A: 

I'm sure there actually are some sites using C++ as backend, however, I expect those are mainly older sites. For instance I know a school in the United Kingdom that relies on a C++ backend, can't say I know the motivation behind it, but it's definitely possible. If I'm not mistaken it's even possible to use the C++ code through IIS as modules, which should give you some advantages over writing the complete server application yourself.

It's doubtful whether anyone would recommend you to use C++ though, it could have quite some performance advantages for some applications. Nonetheless, it'll probably also make it a lot more complicated; languages 'made for the web' come with so many functions and optimizations out of the box, you'd probably be (partly) reinventing the wheel.

Leftblank
+3  A: 

You can do anything in any language. Its a question of using the correct tool for the job. Since websites are mostly about string processing, it makes sense to use a language that has string processing as a strength. Another drawback is that there aren't any/many C++ tools to help.
That said, there is nothing wrong with writing some back-end, number crunching code in C++, and then using another language to interface it to the web. We do this with some heavy-duty, parallel simulation that run on 100 to 10000 node clusters.

KeithB
What kind of string processing cannot be done in C++ easily?
Dimitri C.
Depends on the definition of "easily". If "easy" means "less or simpler code than Perl" then pretty much all string processing in C++ would be considered "hard". At some point, the benefits to program organization may overcome the deficit in string manipulation syntax, but many other languages make string processing much easier than C++.
Ben Voigt
String processing in C++ is not terribly hard. Try boost.spirit, boost.xpressive or tr1.regex, not very different from perl except there is not the so nice syntax around it. Although xpressive is pretty slick.
Raindog
+3  A: 

Why not make websites in C++? Because C++ is a low level language for system programming.

You don't want to think about circular dependencies and object models when making a website - it gains you nothing, as the bottleneck is probably the network or the database.

-1 because C++ as a language is very well suited for building webapps. In webapps, the same as GUI apps, the resources usually go into tree-like hierarchy, allowing you to use auto storage and not worry about "new" and dynamic allocation at all. The statement about DB being the bottle neck is also untrue with scripting languages such as PHP, Ruby and Python, which are so slow that they usually end up being far bigger obstacles than the database backend.
Tronic
I agree with Tronic.
Raindog
+2  A: 

C++ is a general purpose language... but ASP, PHP, etc were DESIGNED to make websites, so they grew to be really popular languages for the web. Many people that "grew up" with ASP (and maybe PHP) moved to ASP.NET (so VB.Net and C#).

I am not a Java guy, so I'm not sure why that particular language grew to be popular with the web. I'm thinking because it was (and is) popular in universities and because Java was one of the first languages to get some real good toolkits for the web.

Giovanni Galbo
Basically because of J2EE and Application Servers like JBoss and Weblogic added a faster way for people to develop secure applications. And of course, because of Java's great popularity.
Ubersoldat
+8  A: 

A lot of web development boils down to database querying and string manipulation. Both of these are easier to do in a dynamic language than in C++. The main reason to use C++ would be for efficiency, though most sites don't need that much efficiency.

Web sites might be written in other languages but call components written in C++, say for number crunching. But the main logic of a site is seldom written in C++.

John D. Cook
+17  A: 

I am primarily a C++ programmer, so I don't intend it as a slam on C++ when I say C# and Java are much more modern languages, better suited for 99% of application development you want to do. The downside of C#/Java/etc. is that the users need big bulky runtimes installed on their PCs, and if your users don't have them then they will have to install them. So it is usually better to write consumer apps in C++, where there will be few dependencies and Grandma won't have to figure out how to install .NET framework 3.0.

For web applications, your user will just be using a web browser so you can write in whatever language platform you want. So why not write in a modern, better language?

(again, before C++ programmers jump all over me, let me say that I have been a primarily C++ programmer for 15+ years. It'd be silly to ignore that modern languages are far easier and better for most application development.)

mhenry1384
I am a C++ programmer and I make a jump when I read that it would be less easy for doing web development ;-) The only downside I can see is good library support, which is not a programming language issue (although it is frequently considered to be one, regrettably :-(
Dimitri C.
As Dimitri C said, the key is not the language, but the library. So far the only feasible C++ web development library is Wt. ATL Server was decent, but it was canned pretty fast.
Raindog
+3  A: 

I suspect these days, C++ might be used in embedded web servers; such as you might find in a router. I have noticed one C++ web development framework called Wt.

Ferruccio
+1  A: 

C++ has poor support for text manipulation (in terms of built-in support) and it is all about manipulating and formatting text on the web. Also the performance bottleneck is in most cases database and network so it doesn't matter much if you write in a speedier language.

I made a webpage in C which does some image processing on uploaded images long time ago. It was pretty performant but thinking now, I could have been more productive seperating the image processing stuff as a cli utility which is called from php/perl/whatever you have in hand.

Also people doesn't want to manage memory themselves. Almost like the Pavlov's dogs, most of us are trained to cry when we hear the word "pointer" throughout our programming lives. So manual memory management is just "bad" for web programming. It is not such a great issue for plain old CGI though. Your CGI will probably need all the memory it allocated for the whole of its short life and just let the OS release it. It may not be the case for an application container (depends on implementation anyway).

Culture around C++ is more varied than relatively newer languages used on web (such as python, ruby, newer versions of php, notable exception is perl which is about doing things differently) thanks to its general scope and age, there is not an obvious "it should be done like this" way which a newbie can pick up quickly and get started.

There is of course things to make web programming with C++ easier, but they are mainly focused on embedded systems. You don't have much choice anyway if you are programming for an small embedded system than manual memory management and squeeze out the last available cycles.

artificialidiot
+6  A: 

Form here: http://www.jroller.com/craiger/entry/where_are_all_the_c

Craig Tataryn wrote: Hi Bjarne, I'm professionaly a Java programmer and was wondering
something. In the Java world, we have Sun, and Sun (or a commitee) produces specifications for things which would benefit the Java
eco-system (if I may use this kitchy terminology). So, two
specifications were produced of significance to the web application developer:

Java Servlet Specification Java Server Pages Specification

Within the Servlet spec, Sun defined the reference framework for what a "Web Application" is, and how, if one were to create a web application container, they could do so by following this spec.

Of course this caught on like wild fire, and whether one likes or dislikes Java, the specs setup a nice environment which cultivated Java as a web-language (dare I say "of choice") for developers.

I have many friends who are C++ programmers, so I queried them as to what type of framework they use to build webapplications. They either a) don't write web applications b) wrote their own framework (http://http://labs.wexussoftware.com/) or c) use Ruby on Rails. The last option was described to me as "use the right tool for the job"

I guess the answer I am looking for is, why hasn't C++ penetrated the web application frontier? Is it lacking an entity to write a
specification for such a thing? In my googling, I can't even find commericial web application frameworks for C++. I just don't get it because it would produce some pretty fast, resource savvy webapps.

You have the answer in the first line "Java has Sun" or maybe more correctly "Sun has Java". That is, there was an organization willing to pay dozens of millions of dollars for development supported by more dozens of dollars for marketing. The C++ community never had that. Instead, many organizations built tools for areas they found important for their own customers.

In consequence, the C++ community don't have massive frameworks (unless you count CORBA), just applications (usually massive applications, such as amazon, google, ebay, and amadeus).

There is a lot of C++ "behind the scenes", e.g. financial software, embedded systems, games, infrastructure (e.g. CORBA, JVM), OS. See my applications page. There just isn't a mechanism for that to be seen (like Java's little coffee cup).

Loki
Library support IMO is what ultimately lead to Java, .NET, Python, Ruby and perl's success and to C++'s fall from glory.
Raindog
+2  A: 

It's not popular because nobody bothered to write a decent template system for it, which is not that hard.

BTW, Google's own web server (from http header: "Server: gws") is written in C++.

ididak
The web server isn't the web application. Sure, IIS, Apache, GWS are all written in C and C++. But then they provide plugin interfaces (which used to be CGI) for more-scripty languages to do the content generation, while C++ is used for transport, caching, compression, encryption, etc.
Ben Voigt
+4  A: 

Aside from Google's search website, Amazon's original setup ("Tradition #1": best link I can find) or eBay from '97 to 2002 (PDF, pages 9-14), it's not common at all. Because, as already pointed out, it wasn't really designed for this. But it's not a bad idea to use C++ to implement some web services (although without built-in XML support, you'll likely send data over the wire in other formats) which your site can then call to.

If you're on IIS, you can use ATL Server.

If you wanted to do it anyway, you'd need a template system (Google ctemplate, from above), and a database access layer. You'd also want to read up on how to hook into your web server (using ISAPI on IIS, Apache modules) if you're going to pass parameters as part of the URI (that is, as "part/of/the/path/to/the/command"). You can use CGI if you're with passing parameters only via GET or POST.

Max Lybbert
A: 

I have a couple of "customer area" websites which are actually ISAPI DLLs written in C++, so it's definitely doable. We still use them because we are building on top of really old (but working) code and also because we can distribute the dll to our distributors without them seeing the underlying source code.

But I have to agree that it's a really clumsy way to build a website. Furthermore, support for ISAPI DLLs has been dropping really fast. Visual Studio 2008 doesn't support them anymore (I don't know about 2005) and it's a real pain to enable them on Vista.

It's a possible solution if you only know C++ and HTML, but there are definitely better alternatives out there.

djeidot
+13  A: 

I recommend to use the C++ webtoolkit Wt (pronounced Witty), at http://www.webtoolkit.eu/.

This framework (with integrated application server) lets you design web applications in terms of widgets and signal/slot connections, and leaves much of the web cruft in the hands of the library. The resulting applications are object-oriented, strictly typed, and perfectly maintainable. The library autodetects the browser's capabilities and uses the proper way to render the site, avoiding browser bugs.

It is not my intention to start a language war, but Wt is written in a modern C++ style, which doesn't need to lead to memory leaks and other mishaps that have always been associated with C++ applications. I agree with the validity of your statement: why not write web applications in C++? C++ is as good as any other language around. It is not a matter of performance, it is a matter of style.

+2  A: 

I think the only reason for not building a web app in C++ is a lack of libraries for it (well-known libraries that is). I don't see what kind of string manipulation, networking or database access that could not be done in C++.

One big advantage of choosing C++ is that if you already have a lot of C/C++ code in your company, it avoids introducing yet another language, which comes with its own IDE, standard library, custom written libraries, programming language quirks and limitations, library quirks, profilers, etc...

Dimitri C.
Nobody seems to understand the importance core language libraries have in the overall success of a language.
Raindog
A: 

To add in a belated response:

OkCupid (dot com) uses C++ for the core of their website. They are both a new (somewhat) and popular website.

Jon
A: 

Check out Google's Native Client SDK, to use native code (e.g. C, C++) to create web apps that run in recent versions of Chromium.

Gerardo
I was more thinking about server backend. But this is noteworthy too.
Vilx-
A: 

A website in C/C++ is a web application - embedded solution. The fastest C/C++ based web application development SDK is Snorkel. http://sites.google.com/site/snorkelembedded

Walt C.