

C++: A language for next generation web apps - TomasSedovic
http://stevehanov.ca/blog/index.php?id=95

======
yummyfajitas
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.

~~~
joe_the_user
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_.

~~~
hazzen
C++ doesn't actually have a standard "hash list" (I assume you meant hash map
or hash set?). Depending on your implementation, you either have
hash_{map,set}, unordered_{map,set}, both, or something entirely different.
tr1 specified unordered_{map,set}, but tr1 is only technically a proposal, not
a standard.

I think a safe assumption is that tr1::unordered_{map,set} will be available
in all implementations by now, but until C++0x is ratified and implemented by
major compilers, you will run into different platforms having (possibly)
different implementations. And lets be honest - even after C++0x has been
implemented in major compilers, you will _still_ have subtly different/buggy
implementations.

 _edit:_ I had conflated {hash,unordered}_{set,map}. Fixed

~~~
queensnake
Nah, the committee isn't going to change unordered_set or unordered_map;
they're struggling with far more urgent things, to finish the std off. Those
have already gotten the full treatment, they have the usual std:: collection
interface; what's to change?

------
derefr
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
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?

~~~
flatline
Sort of - I don't think that the web templates and CodeDom are there like they
are for VB/C#. It's also kind of a mess going between managed and unmanaged
code, which you'd be doing extensively if you want to use the System.Web
namespace. Managing references on the managed heap is an extra hassle that has
a fair amount of complexity. To top it all off, the support for the managed
C++ extensions has been lackluster.

------
d0m
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
> I thought at first that the article was sarcastic

This article definitely is sarcastic.

------
aditya
IIRC OkCupid uses a webserver and application stack that is all C++

Ref: <http://www.okws.org/doku.php?id=okws>

------
brazzy
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
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.

~~~
jbarham
Nonsense. Just because the Python interpreter is written in C does not mean
that you can overrun Python strings and smash the stack like you can w/ C
strings.

~~~
coliveira
Its not just strings, all kinds of data structures are vulnerable. See:
[http://www.hardened-
php.net/hphp/zend_hash_del_key_or_index_...](http://www.hardened-
php.net/hphp/zend_hash_del_key_or_index_vulnerability.html)

------
tlrobinson
_"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
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
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/>

~~~
birger
Interesting to see that you used FreePascal! We are also experimenting with
FreePascal and (fast)CGI. My collegue put up some sample pages:
<http://services.cnoc.nl/lazarus/index/fclweb>

------
metamemetics
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
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
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
"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
I had to read that a few times. What is he talking about?

~~~
tedunangst

        1     wchar_t *
        2     utf2wide(const char *utf)
        3     {
        4        size_t len;
        5        wchar_t *wide;
        6        len = mbstowcs(NULL, utf, 0);
        7        wide = malloc(sizeof(*wide) * (len + 1));
        8        mbstowcs(wide, utf, len);
        9        return wide;
        10     }

~~~
tjake
thats C not C++. geesh :P

~~~
jrockway
I hear C++ can call C functions these days.

~~~
invisible
It's amazing the bridges technology can create these days. _cough_

------
jrockway
Excellent satire.

~~~
aphyr
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
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
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.

~~~
miloshh
My point was indeed that performance can matter, and will matter even more in
the future, since no apparent technological limit on network speed has been
reached so far.

------
geirk
If this guy is really running his web server on an Acer Aspire One 512, as he
says at <http://stevehanov.ca/blog/index.php?id=71> C++ sounds like an
excellent choice.

------
alfredp
if you're on an embedded device, this is actually not a satire

~~~
techiferous
So, serving web pages from an embedded device? Have we finally got to the
"your washing machine is on the Internet" era? :)

~~~
maurycy
I can't wait for the RESTful API for my alarm clock, and washer. ;-)

~~~
jimbokun
For the alarm clock radio with iPod dock I just got for Christmas, I think the
RESTful API would be easier to use than the array of buttons on that thing. My
wife got the old, red-LED clock radio back out because she knew how to set the
alarm on it.

------
joubert
Objc is probably a better candidate because it is so dynamic?

~~~
s-phi-nl
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
That has got to be the dumbest thing I have seen in quite a while. "Smalltalk
is garbage-collected. ObjC deals in raw memory addresses. It's actually less
secure than C, as I see it" shows a level of fail that is beyond explaining.

------
theycallmemorty
Anyone else remember ISAPI?

I still use it. Every day.

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

------
coderdude
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.

------
m0shen
Reminded me of this: <http://code.google.com/p/madfish-webtoolkit/>

------
icefox
Language {x} would be good as a next generation web app if there was web app
libraries. Typically those are not {x}.

------
tweiler
Was anyone else let down that this was a sarcastic thing and not real?

~~~
reedlaw
Why believe it's satire? He's got an actual app already deployed and a full
history of blog posts demonstrating his knowledge and interest in this field.

~~~
reedlaw
Here's a link to the C++ code for his app:
<http://stevehanov.ca/blog/index.php?id=8>

------
akadien
I just drank a couple of Pliny the Elders with my neighbor, and now I read
this. My head is definitely spinning now.

------
ozten
Ending up at C++ because of design constraints is understandable... starting
there is idiocy.

------
rbanffy
I missed the <sarcasm> tag.

~~~
astine
From the article:

 _I gave a_ tongue-in-cheek _talk on how C++ can fit in to a web application._

~~~
rbanffy
The thruth is, my company maintains a C++ we application. It's implemented as
an Apache module and employs some very interesting in-memory shared
structures.

And, like I said, I missed that part.

It was not proper markup ;-)

------
spektom
He's lying, C++ apps are not portable.

