8 ms·
C++: A language for next generation web apps
- khelloworld 17y ago"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 17y agoI had to read that a few times. What is he talking about?
- tedunangst 17y ago1 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 }
- jrockway 17y agoExcellent satire.
- aphyr 17y agoI 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.
- deleted 17y ago[deleted]
- rbanffy 17y agoI missed the <sarcasm> tag.
- coderdude 17y agoHe forgot to encode the character entities.
- astine 17y agoFrom the article: I gave a tongue-in-cheek talk on how C++ can fit in to a web application.
- deleted 17y ago[deleted]
- rbanffy 17y agoThe 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 ;-)
- alfredp 17y agoif you're on an embedded device, this is actually not a satire
- Avshalom 17y agoon that note does anyone know of an ansi Forth (or fairly portable at least) server that's reasonably robust.
- csmeder 17y agohttp://colorforth.com/haypress.htm http://colorforth.com/haypress.htm I'm not sure if this falls under the robust category or.. sever :) but it supports forth and has total of 360 computers running at 700 Mips or 250 Gips
- kls 17y agoWhich 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.
- techiferous 17y agoSo, serving web pages from an embedded device? Have we finally got to the "your washing machine is on the Internet" era? :)
- branden 17y agoIt's not exactly Facebook, but I've seen plenty of small network-connected appliances provide web admin interfaces. Routers are a common example, I've also used network console servers that do this.
- maurycy 17y agoI can't wait for the RESTful API for my alarm clock, and washer. ;-)
- 17y ago
- coderdude 17y agoI 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.
- derefr 17y agoIt'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 17y agoI 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 17y agoSort 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.
- yummyfajitas 17y agoTo 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 17y agoOddly 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 17y agoC++ 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 17y agoNah, 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?
- m0shen 17y agoReminded me of this: http://code.google.com/p/madfish-webtoolkit/ http://code.google.com/p/madfish-webtoolkit/
- tlrobinson 17y ago"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 17y agoI 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.
- theycallmemorty 17y agoAnyone else remember ISAPI? I still use it. Every day. It really isn't as terrible as you'd think.
- miloshh 17y agoThe 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 17y agoRoundtrip 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 17y agoMy 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.
- tweiler 17y agoWas anyone else let down that this was a sarcastic thing and not real?
- Imprecate 17y agoCheck out OKWS (http://www.okws.org/doku.php?id=okws http://www.okws.org/doku.php?id=okws) if you're interested in developing webapps on C++.
- reedlaw 17y agoWhy 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 17y agoHere's a link to the C++ code for his app: http://stevehanov.ca/blog/index.php?id=8 http://stevehanov.ca/blog/index.php?id=8
- d0m 17y agoI 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 17y ago> I thought at first that the article was sarcastic This article definitely is sarcastic.
- akadien 17y agoI just drank a couple of Pliny the Elders with my neighbor, and now I read this. My head is definitely spinning now.
- ozten 17y agoEnding up at C++ because of design constraints is understandable... starting there is idiocy.
- icefox 17y agoLanguage {x} would be good as a next generation web app if there was web app libraries. Typically those are not {x}.
- aditya 17y agoIIRC OkCupid uses a webserver and application stack that is all C++ Ref: http://www.okws.org/doku.php?id=okws http://www.okws.org/doku.php?id=okws
- badsectoracula 17y agoFor 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/ http://www.badsectoracula.com/projects/mforum/
- birger 17y agoInteresting 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 http://services.cnoc.nl/lazarus/index/fclweb
- fudgie 17y agoWay back in 2000, when we launched Planetarion (http://en.wikipedia.org/wiki/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.
- spektom 17y agoHe's lying, C++ apps are not portable.
- metamemetics 17y agoLet'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.
- brazzy 17y agoWhat 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 17y agoSuch 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 17y agoNonsense. 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.
- alnayyir 17y agoI smack my lips in expectation of the usage of gets() in web apps.
- coliveira 17y agoIts not just strings, all kinds of data structures are vulnerable. See: http://www.hardened-php.net/hphp/zend_hash_del_key_or_index_vulnerability.html http://www.hardened-php.net/hphp/zend_hash_del_key_or_index_...
- geirk 17y agoIf 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 http://stevehanov.ca/blog/index.php?id=71 C++ sounds like an excellent choice.
- bad_user 17y agoHe 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 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.
- joubert 17y agoObjc is probably a better candidate because it is so dynamic?
- s-phi-nl 17y agoSee http://news.ycombinator.com/item?id=1046516 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 17y agoThat 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.
- protomyth 17y agoI do sometime wish Apple would bring back the original WebObjects framework with EOF. The Java version is not much fun.