views:

1631

answers:

19

A lot of People see similarities between Java and C++ .

But when it comes to web development JavaEE is beeing used. Whereas C++ has little support on that? C++ is fast. So why it isn't used in web developement?

+24  A: 

C++ may be fast in execution speed, but Java, C#, PHP, etc are faster in time to market.

jrcs3
I disageree. You could also make a Object.buildMeAFancyWebsite - method in C++,too.
n00ki3
Darth
disagree all you like but in truth C++ requires more lines of code to do the same thing as a high-level language, and typically is harder to debug and prototype.
SpliFF
@SpliFF: Typically, C++ requires approximately the same amount of code or less compared to Java and C# in particular, due to the lack of need for try...finally for cleaning up resources. Java and C# code pays a penalty in clean-up code duplication, whereas in C++ you write it once and forget about it, and it gets called automatically. C++ is a high-level language, albeit with low-level capabilities that are used more often than they should be. The bigger advantage to Java and C# is that they have large libraries already written for them that come with the compiler.
Joel
@Joel - if you have that many try...finallys in your C# you're doing it wrong. Even a cursory glance at C++ vs C# shows C# to be lighter.
annakata
@annakata: Experience shows that people use far fewer of them than they should. Using a class that implements IDisposable means you're supposed to call Dispose on it - you can't rely on the finalizer. The using construct in C# simplifies things, but it's still, ironically, manual resource management in a way that C++ doesn't require. Looking at a fair amount of C++ code that's out there, yes, it would appear to require more lines of code. But there's also a fair amount of bad C++ programmers out there. However, hands down, Java and C# win on out-of-the-box libraries.
Joel
+7  A: 

C++ used to be a common language for web development. At the time, however, there were few viable alternatives. Languages such as C# and Java are designed for application development instead of being general purpose, so they're a better choice for web apps.

Steven Sudit
+14  A: 

IMHO, it's all about the tool chain. Java, Ruby, etc. have mature tool chains for web development. The tools make development faster in most cases. There are some environments for C++ but none have widespread usage. The other major reason for this is that most of the newer languages are developed for application development first and general purpose computing second.

D.Shawley
A: 

Imagine you need a site. There is two options available to you: 1. Pay x amount of money and develop a site within y amount of time using .net/java/python/ruby/ect. 2. Pay x*n amount of money and develop within y*m amount of time using C++ (FastCGI). Wheres n and m are 3-5+. What would you prefer?

Ray
+3  A: 

For one thing, the java and C# libraries/frameworks are much, much bigger than C++. "Standard" C++ has almost nothing interesting for web development. THe standard C++ library does not even have the slightest thing related to network, threading or portable file system access. I doubt C++ speed is much of a factor: java and C# are generally as fast as C++ in server settings (where you can use the full JIT capabilities of the runtimes, because starting times and co are of no concern).

David Cournapeau
Java is EXTREMELY SLOW compared to C# and C++
ראובן
@ראובן It's not true. Java and .NET are very close in the mean of performance to each other.
Ray
the claim that java is extremely slow compare to C#/C++ is laughable at best. There are several examples where C programs reimplemented in java which ended up even faster (cmu sphinx engine, for example). Of course, that won't always be true, but there is a widespread belief that C/C++ are the kings of speed, which is really not true, especially in practice when you have finite time to get to your result. Only thinking about string handling, such a common task in web devlopment, and so painful in C and C++.
David Cournapeau
@David Cournapeau: string handling is typically done very poorly in Java and C#, not because the languages don't handle it well but because most developers use the wrong tool (the + and += operators on the String classes, rather than StringBuilder in C#, which has been demonstrated to incur a huge performance hit if you manipulate a lot of strings). Moreover, since the advent of the STL string class (over 10 years ago), string handling is barely any more painful in C++ than in Java or C# (it's mildly painful usually when dealing with C APIs or trying to concatenate literals).
Joel
This "Java is extremely slow" nonsense is just nonsensical nonsense. Java has garbage collection, which means that object creation is cheaper than in C++. This means that you can write complicated, performance-sensitive code without worrying about reusing objects, you can simply allocate this array again. This makes your code clearer.
quant_dev
+46  A: 

Oftentimes the possibly faster execution speed of C++ doesn't matter since the bottleneck is the database and network I/O.

So the benefits from ease / speed of development, safety (really sucks when your web app core dumps), and availability of frameworks will outweigh execution speed gains for many applications.

Karl Voigtland
<- this
annakata
Databases with C++. Tons of fun...
Partial
On the other side if only there would be some sort of portable framework for C++ to ease database and network management it could make the whole thing possible...
Partial
+3  A: 

I once worked on a extremely high-performance web site done in C++ with a custom framework. We weren't using Apache--we had a domain-specific web server that could serve our special content fast and efficiently that was hand-coded in C++.

This server processed requests that came in from what was, at the time, the highest rated prime-time television show. (The host would say "log in to ......com to play along). Instantly, 100,000 or more people would be pounding the server. One ordinary PC was able to handle the load, but we had 3 running, just in case one went down, etc.

Fact is, the systems we use for Web development now are extremely wasteful. We're trading CPU cycles for ease of maintainability.

Take a look at architectures like http://acme.com/software/thttpd/ which are extremely fast web servers.

ראובן
and this is good. What is the biggest constant in development? It is our friend Change. So having frameworks that make you application easy to maintain/customize is a huge benefit. If my server is getting slow...I just put another one next to it and enable some load-balancing. The Hardware is cheaper than having 10 people spending weeks on customizing a fast but complicated low-level application.
lostiniceland
CPU cycles are MUCH cheaper than development time. If it were otherwise do you really think an entire sub-species of development would have sprung up? No, we'd all be working with C++ if it *was* the appropriate tool.
annakata
we may not think about the same thing: when I hear web development, I don't hear web-server. I would not put apache or thttpd into the web development category.
David Cournapeau
+11  A: 

If you'd ever had to develop a web application in C++ you'd know why. Basically, there is nothing approaching the frameworks that .NET, Java or PHP have nor is there anything web-specific like ROR or Django.

Dan Diplo
Wt isn't half bad: http://www.webtoolkit.eu/wt
Evan Teran
The more interesting question is why there wasn't any libraries developed - C++ was used for web for 5years before Java an 15years before Ruby/PHP etc
Martin Beckett
The more *more* interesting question is why was Java created if C++ was in use already for the same purpose and good enough?
annakata
baeltazor
+2  A: 

Web development is full of people who got where they are from editing HTML, and has far fewer people who got there from C++, or C. The tendency then for most of these web developers, is to select simpler languages with garbage collection, that prioritise quick results over performance. C++ is really really not a langauge like that.

But that's only a superficial reading. Mostly it's about fashion.

Breton
IMHO and in my experience this simply isn't true. Some particular cultures (PHP springs to mind) do have a designer->developer skew, but C# and Java? You, my friend, have not seen the kind of front end code those people produce. Denouncing !C++ languages as fashionable is going waaaay off the res.
annakata
especially since gc is one of the thing which will make java/C# faster than C/C++, for things like string manipulation :)
David Cournapeau
@annakata you're probably right. nevertheless, I still thing garbage collection might be a huge factor, as manually managing memory is a huge burden, and with webdevelopment there isn't enough of an emphasis on realtime performance to cause someone to shun GC. People don't worry about GC pauses while a page is loading: That shit is slow anyway, who would notice?
Breton
Java is much easier to debug than C++.
quant_dev
+1  A: 

Because the C++ is hard to learn.

grigy
Rather because it's hard to use, and that comes mainly due to poor (relatively) standard library feature-set.
Ray
I think this is exagerated. I don't find it much harder than Java for example. Additionally, C# for example has a lot of quirks too.
Dimitri C.
A: 

C++ is not very handy for web development, because the programmer has to take into account that objects are destructed properly. In languages like C# and JAVA there is no need to create destructors, because instantiated objects only live in a certain scope. So in a pratical way you could say languages like C# and JAVA are more useful for web applications than C++.

Robin Buitenhuis
In C++, writing destructors has pretty much nothing to do with the actual memory management. If you have a destructor but don't call delete, then your object will stay in memory and the destructor won't even be run.
lhahne
Modern C++ programs are too using mainly automatic memory management - by wraping classes into various smart pointer implementations (mainly by references counting).
Ray
-1 In Java and C# your finalizers get called too late (unless you wrap everything in C# using blocks) which means that they cannot be used properly. In C++ auto storage objects (which is what you normally use) destruction always happens at the right time and in the right order (the exact reverse of construction) and the process is correct even when exceptions are being thrown during construction of objects or otherwise.
Tronic
+9  A: 

I'd go with Karl Voigtland's answer (though I like Dan Diplo's too) but I wanted to add that I personally work for a company where speed is everything (in a comparable to google kind of way) and I still wouldn't use C++ for the web-app because the performance difference would be absolutely negligible, especially compared to the I/O bottleneck and network latency which is the real problem anyway.

C++ costs you a standard, well-documented, widely used framework (whichever one that happens to be) which makes up an enormous chunk of the work you'd have to replicate, and puts you firmly into the territory of crashing your server if something goes wrong.

So much effort and so much risk for no gain whatsoever. C++ is a weapon for an older more civilised age, it's not for the web.

annakata
+1 for weaving in a SW reference!
p.campbell
A: 

For every type of job you need an appropriate tool. It is possible to drive a nail into a board by hitting it with a pair of pliers, but a hammer is much better suited for it.

Dima
Wait, an analogy where C++ isn't the hammer?
tstenner
+1  A: 

because I would want to jump out the window every morning I would come to work.

Agreed that frameworks are important and solve a LOT of typical problems for you. c++ won't have those frameworks for you. Also, you may be optimizing performance at one level but this may not lead to the most optimal solution. DB access time is, with a larger site, likely a much larger concern and one that's most likely worth worrying more about than your application execution time.

Also, you're talking about web development where things change quickly. c++ is not the language of choice in this field and you'd be left standing still trying to catch up with the rest of the crowd that plays well together.

Stick with the crowd, use what's out there. Don't optimize locally. You're better off.

pcresswell
+1  A: 

.... maybe another question could be asked. Do C/C++ developers write web apps, and if and when they do, do they use C++ or something else?

vector
+4  A: 

I'm building a browser game in C++, and yes, some parts definitively suck (such as using FastCGI, which does not support multiple connections at once, unless you're implementing your own FastCGI-Handler, CGI even worse, SCGI doesn't support multiplexing either (but is a charm to implement) and using a custom server API isn't portable), however, once you have the environment set up, developing isn't that difficult.

For example, the following code prints out all cookies:

for( map<string,string>::const_iterator it=data[cookie].begin(); it!=data[cookie].end(); ++it)
{
    cout << "<b>" << it->first << "</b>: " << it->second << "<br>\n";
}

Or, if you want to design web applications as you would with Qt, take a look at Wt, which reduces the pain of developing C++-Webapplications to the manual memory management.

tstenner
Wt does automatic memory management.
Tronic
+1  A: 

Because Web development involves a lot of HTML. In the old days of Java, there was only Servlet and this was counterproductive. So they invented JSP.

C++ is even worse than Servlet from that viewpoint.

And in the very old days Assembly Guys did pretend C++ was lame and that using Assembly Languages was much better so your question pertains to the same kind of perspective.

programmernovice
+2  A: 

When the web first came out speed wasn't a big deal. We ran the servers on Unix machines that had more than enough power to fill a 10Mb ethernet. The handfull of users were on dialup and the sites were mostly text. So we used Perl, just because it was easy to do string manipulation, some of us even used TCL (shudder).

By the time the web took off enough to need bigger more complex systems the dynamic languages had got better and came with lots of helpful libs (especially Perl). Then business bought into Java in a big way - Sun actually managed to market something!.

There's no reason we couldn't have all the web features of Java / C# in C++ but the libs weren't developed or never gained wide traction.

There was a lot of web development in C++ but it was generally in custom web servers for very high performance tasks.

Martin Beckett
A: 

Another reason is that is a lot easier to write subtly insecure code (buffer overruns etc) in C++ than in languages with proper bounds checking that abstract raw memory away from the developer. C++ requires a great deal more skill to use safely than the alternatives.

"C++ requires a great deal more skill to use safely than the alternatives." This is true, although I doubt this is a problem for full time programmers.
Dimitri C.