Ask HN: Do you C++ for Web App Dev?
6 comments
No, I don't use C++. But all of my code for Tarsnap (including website) is written in C, aside from a few very small shell scripts.
Perhaps a good C++ programmer writes equivalent code in C++ just as fast as he would in Python (For some kind of tasks I've found this to be true as well), but how many good C++ programmers are there? It's a brutally tricky language and getting quick requires knowing how to avoid the sometimes subtle pitfalls.
I suspect that for the vast majority of web apps though, PHP, C#, Rails, whatever is 'good enough' and they run into the db as a bottleneck if anything and would rather scale out their scripting layer with more machines. The framework ecosystem around C++ as a web app language also isn't as rich, so it requires more work to get started.
I suspect that for the vast majority of web apps though, PHP, C#, Rails, whatever is 'good enough' and they run into the db as a bottleneck if anything and would rather scale out their scripting layer with more machines. The framework ecosystem around C++ as a web app language also isn't as rich, so it requires more work to get started.
Long post is long. I don't see any big advantage to using C++ vs Java - performance is similar with recent optimizations and the vast majority of web services and libraries support java.
Re: development time, you must have a pretty fast compiler. One big argument in favor of dynamic languages is the shortened edit/compile/test cycle; it's down to edit/test.
Re: speed, I think the prevailing wisdom is "write the damn thing in Python and if it's too slow, we'll profile it and write the tiny bit that needs to be fast in C or C++". You still have to do this with C++ -- native code does not magically make your application bottleneck-free.
Re: speed, I think the prevailing wisdom is "write the damn thing in Python and if it's too slow, we'll profile it and write the tiny bit that needs to be fast in C or C++". You still have to do this with C++ -- native code does not magically make your application bottleneck-free.
If there was a good, straightforward Mongrel-type HTTP service builder for C++ it might be more popular.
There is, FastCGI.
On the FastCGI module to the web server (eg. Apache) you can configure the number of processes to spawn for that application, and the FastCGI library will also provide you with many routines to take care of the input, output, and http header parameter handling.
(I hope that's what you meant by Mongrel like HTTP service builder, assumed you were talking about the clustering using it)
On the FastCGI module to the web server (eg. Apache) you can configure the number of processes to spawn for that application, and the FastCGI library will also provide you with many routines to take care of the input, output, and http header parameter handling.
(I hope that's what you meant by Mongrel like HTTP service builder, assumed you were talking about the clustering using it)
No, that is absolutely not what is meant by "Mongrel-type".
FastCGI != HTTP. There is no good reason for FastCGI to exist, it doesn't do anything HTTP wouldn't do better.
FastCGI != HTTP. There is no good reason for FastCGI to exist, it doesn't do anything HTTP wouldn't do better.
There is no good reason for FastCGI to exist, it doesn't do anything HTTP wouldn't do better.
Not true. The FastCGI interface is much simpler than the HTTP interface, which makes it much less bug-prone.
Not true. The FastCGI interface is much simpler than the HTTP interface, which makes it much less bug-prone.
fastcgi++: http://www.nongnu.org/fastcgipp/
It's a pretty bad choice for using on frontend of sites, but for backend stuff where you have CPU bound tasks it's great. Lean and Fast. But when ever I bring this subject up, I get weird or confused looks...
* Some reasons I am given is that it's complicated. Not really, writing web applications in C was complicated, but with the C++ STL and Boost, lot of your generic things are a breeze like string manip, not to mention the millions of other libraries out there.
* Development time: For me writing a Python or PHP app that does the same thing takes equally the same amount of time as writing it in C++. (this is for backend related stuff like computations and other CPU hard stuff, not front end)
* Other's are equally fast. They can be, but you have to add additional layers on top, accelerators, caching systems, etc etc and make sure everything is all optimized. A lot of things on top of what you would normally do to achieve a C++ level app aperformance
C++ with FastCGI is a excellent choice for backend development, yet it's so rare. I don't even recall a single time this was brought up during web development talk or conference.
Why do you think this is?
(Backstory: The backend for our project is a lot of C/C++ on FastCGI on Apache. My workflow usually consists of Pyhton for prototyping and verification of design, then writing it in C++ for production, the speed is not even comparable).