top | item 1079286

C++: A language for next generation web apps

104 points| TomasSedovic | 16 years ago |stevehanov.ca

95 comments

order
[+] yummyfajitas|16 years ago|reply
To be fair, after coming back to C++ after years in the world of Python and Haskell, it's not as bad as I remembered.

C++ is actually a moderately effective functional programming language. With reasonable knowledge of the standard data structures, and using BOOST, one can actually write fairly expressive and effective C++ code.

Most of the time, I feel like all I'm doing is writing a much more verbose version of Python. The rest of the time, I'm hunting nightmarish segfaults and segfault and template errors.

[+] SamAtt|16 years ago|reply
The question isn't "Can C++ work?" or "Will C++ be faster?" because we all know it can work and that it will be faster. The question is "At what point does the extra development time become more expensive than just adding another server to my Ruby/Python/C#/Whatever App"

For me, someone who learned C++ in school but has been in managed enviornments ever since, I'd be too scared to use C++. I'm not ashamed to admit I get a lot of help from the Internet when I'm stuck on a problem and that help is available because everyone else is using the same tools I am. Using C++ to code web apps puts you out in the wilderness as far as I'm concerned and I just don't think I could do it.

[+] abrahamsen|16 years ago|reply
Your experience with Python and Haskell has most likely made you a far better C++ programmer than you were before.
[+] joe_the_user|16 years ago|reply
Oddly enough I'm back to C++ too, after Ruby.

One nice thing is; in a fast language, tests run quickly too.

Also, Python and Ruby don't have the equivalent of an ASSERT (you could roll your own but it's not standard practice).

Also, C++ has standard hash lists and complicated data structure are actually going to run quickly.

And while memory management can be a pain, you are doing it yourself so you can track down memory leaks rather than having them be inherent in the interpreter...

...as in Ruby AND Mono.

[+] capablanca|16 years ago|reply
So, what is great, modern C++ code to read?
[+] derefr|16 years ago|reply
It's perfectly sane to write web services (computationally heavy processes accessed via REST) in C++. But for the algorithm-light, marketing-heavy frontend to such a service, use something easier—the optimizations C++ offers aren't worth it there.
[+] Devilboy|16 years ago|reply
I don't have any experience with it, but I'm under the impression that MSVC / C++.net has all the goodies you'd need to do the easy frontend stuff also?
[+] d0m|16 years ago|reply
I thought at first that the article was sarcastic :-| I mean, what's taking time is not whether you use ruby python or c++ but the http request, request to the DB, IO or javascript loading..

And anyway, the part that really need to be optimized can still be done in C even if you use python.

There was a time I was a C++ guy who wanted to control memory and everything.. but now, I've got other things to do. If I can write 1 line that is more readable and cost less to type, why should I use C++ ?

And by the way, C++ isn't a verbose python. And, even if I once thought that boost was the best thing ever made, I feel that it's a waste of time. Instead of using meta-programming hacks to use lambda in a clumpsy/ugly way, why not simply use python or scheme ?

[+] gphil|16 years ago|reply
> I thought at first that the article was sarcastic

This article definitely is sarcastic.

[+] brazzy|16 years ago|reply
What has not been mentioned at all: how C++ webapps will spell the end of XSS and SQL injection as hackers refocus on the much more interesing but almost-forgotten buffer overflow vulnerabilities.

Oh joy!

[+] coliveira|16 years ago|reply
Such vulnerabilities still exist in PHP, Python and Ruby, because they are written in C. And they are much easier to exploit because almost every web app uses one of these languages.
[+] tlrobinson|16 years ago|reply
"MySql is GPL'd, so you can't even link to its client library in a closed source app."

AFAIK it's GPLv2 (and not AGPL) so this is only true if you intend to distribute your application itself, not just host it yourself.

[+] lemming|16 years ago|reply
I believe it does however mean that your application code has to be GPLv2, and thus can't be linked to code using some popular licenses, for example Apache 2.0.
[+] badsectoracula|16 years ago|reply
For a two to three years i was running in a VPS server in VPSLink which had about 64MB of RAM - for everything and without swap space. The target use of this VPS was probably as an email server or something as most people recommended the more expensive 128MB and 256MB plans for serving (static) pages. And actually there were only about 40MB left since the OS needed some memory for itself too.

Personally i thought that with better resources management i could do much more, so i wrote a custom HTTP server in that could fit in less than one MB of RAM. Most of my pages were generated offline using a custom program in FreePascal.

The server could also execute CGI scripts, so i also wrote a forum in FreePascal.

According to my logs, the whole system ran out of memory only once :-). Until the day i decided to give myself a little more features (when i got a much better VPS from Linode) i had about 5-6 sites running (different domains), a Subversion server and a few "dynamic" apps.

The forum can be found here. I still run it in my new VPS, although it got some spam. The a + b = ? anti-spam feature was new when i wrote the forum but seems that bots got better :-P.

http://www.badsectoracula.com/projects/mforum/

[+] metamemetics|16 years ago|reply
Let's say C++ can code be executed OVER 9000% faster than python.

However this does not imply a web app written in C++ will run even 1% faster than a web app written in python unless the performance bottleneck is code execution.

If the performance bottleneck is instead the database server (which it almost always is) then choosing C++ for your next webapp would be a _very_ masochistic premature optimization.

[+] fudgie|16 years ago|reply
Way back in 2000, when we launched Planetarion (http://en.wikipedia.org/wiki/Planetarion), we used C++ with a custom webframework, and CORBA for communicating with the database.

At our peak late in 2002, we served about 320 million dynamic webpages a month using three desktop Pentium 3's for webservers, and a dual CPU P3 for the database. No caching, as that wasn't needed.

Blazing fast, and not all that difficult to work with once the basic framework was solid and in place.

[+] bad_user|16 years ago|reply
He does have a point about efficiency, or about delivering a single app ... but you also get those advantages with a Java, or a .NET, or even an Erlang or Haskell app which are reasonably efficient ... and still, you won't have to deal with segfaults.

Also, if you want extreme scalability, like being able to serve 10000 requests/sec on a single server ... sorry, but raw performance doesn't cut it ... see this article for instance ... http://www.kegel.com/c10k.html.

Not to mention that the most usual bottleneck is the database (how many apps can you build that doesn't use one?). So even if you build the fastest web server in the world, if you're using a RDBMS you're going to end up with 100 reqs/sec, unless you're sharding or caching that data.

The bottom line is ... if you want extreme scalability, I don't think C++ is going to cut it, and you're going to invest a whole lot more in optimizations that are already done in more mature web frameworks.

Well, unless you have Google's resources and skill.

[+] khelloworld|16 years ago|reply
"Also, as often overlooked by anyone over 30, you have to handle UTF8 to Unicode conversion, but this is easily achieved in a 10 line function."

lol.

[+] olliesaunders|16 years ago|reply
I had to read that a few times. What is he talking about?
[+] jrockway|16 years ago|reply
Excellent satire.
[+] aphyr|16 years ago|reply
I thought so too, until I got to the part where he claims it's running rhymebrain! Still can't figure out whether he's joking or not. Naw, on second reading, definitely sarcasm.
[+] miloshh|16 years ago|reply
The reason why dynamic scripting languages are more appropriate for web applications than C++ is simply that the bottleneck is somewhere else - namely, the Internet is slow enough to make the performance of the server-side code irrelevant. That can very easily change in the future.
[+] barrkel|16 years ago|reply
Roundtrip latency is certainly going to add up to a substantial chunk of time, but that's not much excuse to discard performance considerations. Requests that take say 50ms of processing will take even longer if the box is busy; it doesn't take much to add up and becomes noticeable.

And if your implementation on the server side is very fast, you can do more.

[+] alfredp|16 years ago|reply
if you're on an embedded device, this is actually not a satire
[+] tptacek|16 years ago|reply
I've worked on a lot of embedded devices with web services, and it seems pretty typical to just run a JVM and serve web pages out of it.

The few times I've seen actual web stacks done in C++, the end result has been... comedic.

[+] loup-vaillant|16 years ago|reply
Current embedded devices are likely to have at least 256Mb of RAM, 4Gb of Flash, and as much MIPS as a Pentium III. Not so "embedded" any more, don't you think? If Portability is an issue, then I am likely to use C with something like Lua. But I can't imagine for a second abandoning garbage collection before I see proof I can't afford it.
[+] techiferous|16 years ago|reply
So, serving web pages from an embedded device? Have we finally got to the "your washing machine is on the Internet" era? :)
[+] kls|16 years ago|reply
Which is a very valid point, I have never understood why organizations that need massive scalability for simple, stateless, distributed apps would not pursue such a course.
[+] Avshalom|16 years ago|reply
on that note does anyone know of an ansi Forth (or fairly portable at least) server that's reasonably robust.
[+] joubert|16 years ago|reply
Objc is probably a better candidate because it is so dynamic?
[+] s-phi-nl|16 years ago|reply
See http://news.ycombinator.com/item?id=1046516

  Web apps in Objective C --- the second-least safe programming language
  on the market. Oh please, oh please, build your next huge application
  in this. College tuition for my kids is freaking me out.
[+] protomyth|16 years ago|reply
I do sometime wish Apple would bring back the original WebObjects framework with EOF. The Java version is not much fun.
[+] theycallmemorty|16 years ago|reply
Anyone else remember ISAPI?

I still use it. Every day.

It really isn't as terrible as you'd think.

[+] coderdude|16 years ago|reply
I think he does a good job of humorously pointing out the difficulties involved with writing a C++ Webapp, but I don't doubt that he's serious about the performance characteristics being a good thing.