What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job.
Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks).
C++ compiles directly to a machine's native code, allowing it to be one of the fastest languages in the world, if optimized. On the other hand, PHP is detailed as "A popular general-purpose scripting language that is especially suited to web development".
On average, the PHP version is faster than the ASP version, while the CGI (C++) version is more than 10 times faster than both PHP and ASP.
scripting languages may be slower than C, but is this a problem? almost never. and if the performance becomes a problem, you start to translate only the critical parts.
twitter/ruby is a good example; ruby is slow. some of the language features (that make ruby nice in the first place) just prevent different kinds of optimization (there is a great article by the jruby guy about this ... was it ola bini? can't remember).
still, twitter is powered by ruby, because ruby is fast enough. not long ago, "the blogs" reported twitter migrating to scala for performance reasons ... the truth was, only the messaging queue (and other parts of the backend) moved to scala. yahoo runs on a mixture of languages; php for the frontend, other, faster languages are used where performance is critical.
so, why is performance not that important? there are several reasons:
another pro-scripting point: many of the scripting languages support inlining or inclusion of fast (C) code:
i think, especially in web developement the pros of high-level scripting far outweight the cons.
Several years ago, I more or less learned web app programming on the job. C was the main language I knew, so I wrote the (fairly large-scale) web app in C. Bad mistake. C's string handling and memory management is tedious, and together with my lack of experience in web apps, it quickly became a hard-to-maintain project.
C++ would be significantly better, mainly because std::string
is much nicer than char*
.
However, now I'd use Python every time (though PHP is not a terrible choice, and perhaps easier to get started with). Python's string handling is awesome, and it handles Unicode seamlessly. Python has much better web tools and frameworks than C++, and its regex handling and standard libraries (urllib, email, etc) work very well. And you don't have to worry about memory management.
I'd probably only use C or C++ for a web app if I was severely RAM-constrained (like on an embedded micro) or if I worked at Google and was coding a search engine that was going to have to respond to thousands of queries per second.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With