|
|
![]() |
Web Sequence Diagrams
Create sequence diagrams in seconds for free.http://www.websequencediagrams.com Why was this ad not blocked? |
There were other cool presentations there too. Check it oot! Er, out!

During this presentation, I hope to convince you that the C++ programming language is ideal for developing your next web application.
You might be asking, Steve, Why C++? Why would I subject myself to this horrible language where you have to manage your own memory?
One reason is efficiency. Not only is C++ inherently fast. It also forces you to think differently. It discourages the use of overly complicated data structures that are built in to other languages. In C++, nesting more than one or two structures results in something that is simply too awkward to use. Instead, the you are forced to seriously consider using the simplest possible representation.
In addition, just about any library that you'd want to use has already been written, and has a free implementation available on the internet. Json, and CGI decoders are freely available. Also, as often overlooked, you have to handle UTF8 to Wide-character conversion, but this is easily achieved in a 10 line function.
The only thing you do have to be careful with is SQL database access. MySql is GPL'd, so you can't even link to its client library in a closed source app. SQLite seems to be free, except if you do business in Germany it is $1000 because they have a different definition of public domain.
Here is the first strategy that you might use to incorporate C++ into your web app. In this diagram, there are two things between the browser and your application -- the web server, and the php script. It is not as efficient as it could be, and there are also security implications with calling command line programs from php.
In this model, you write your C++ program as a CGI script directly, using one of the freely available query string parsing libraries. It is efficient and clean. When your browser requests information, the webserver starts your program, which spits out the response in json format. This response is then relayed back to the browser.
I use the above strategy for RhymeBrain. It includes some pretty hairy statistical algorithms that let it sound out any word that you put in. For example, you can enter the word "postrank" and see that it rhymes with such gems as "blank, prank, drank, tanked, and stank".
Because it's written in C++, I can run it on my super-powerful datacenter. It sits atop my sock drawer at RhymeBrain headquarters.
This powerful 1GHz beast can load the entire 260,000 word database and fire back the response in about 12 milliseconds. It does this from a cold start, for each request.
But there is a third strategy: If you write your own webserver, you can cut out the middleman and serve the request directly. Your javascript code makes a request, and all your web server has to do is call a function to send back the results.
Writing a webserver isn't that hard. Here is the complete implementation of the Hibachi web server. It supports virtual hosts, and perl and php scripting, among other things. It was written by former Waterloo-ite Anthony Howe, and won the 2004 International Obfuscated C Coding Competition.
Inspired by Hibachi, I wrote my own webserver and built WebSequenceDiagrams (which runs in a real data center..). Doing it this way reveals a new business model. It is possible to package up the entire web application into a single installer that runs on Windows and Linux. Since it's all integrated, there is no need for customers to fuss around with Apache or the numerous other moving parts that could break if I shipped separate components. (You can run it in your organization for as little as $99).
The only disadvantage is that the final executable is really small -- around 700K. It may be a little smaller than some customers are expecting. During the presentation, it was suggested that I ship it as an appliance, in a huge box, to compensate.
Want more programming tech talk?









Conclusion
I hope that I've convinced you of the benefits of C++ in your next web application:
Follow on Google Buzz
Subscribe to posts
why not just extend with c/c++ servers like nginx/lighttpd?
>have to handle UTF8 to Unicode conversion
Maybe anyone over 30 knows the difference between encoding and character set?
It could be easly done if the C++ was compiled to IL first.
Have a look at my jsc compiler at jsc.sf.net :) It will translate IL to javascript and more!
I do like the idea of a multitier application written as one application.
The main bottlenecks were transfering the data from the logging applications' own memory into MySQL (since MySQL wasn't fast enough to handle 1GB/sec), and the TCP/IP connection between servers (I think we had a 1GBit/connection).
But don't get me wrong, Java is great for some things. For one without Java, the semiconductor industry would lose billions.
Java manages your memory by using more memory. Memory management is overrated. Most Java programs which do very little take up 100's of MB's, and leak, and when the garbage collector does work, it works hard (causes slow down).
In Java you may have a bug and the app still runs/leaks memory, in C if you have a bug it'll crash. I'd rather crash my car, and then take extra care on the roads, than have cancer and not no about it, until it's too late.
Java programs are slower too, which means you need more powerful CPU's. Java encourages a lazy way of coding and architecture, which will bite you in the a** in the long run.
C/++ code is portable ever heard of GCC, works on windows, linux, and just about everything? Tell me when someone makes a Java app for the iphone.
No offense to the wave of java kids out there. But there is a bigger difference between programmers who have an Assembly/C/C++ background and those that don't. Than there is between those who have a Java background and those who don't. Assembly/C/C++ foster a better, more critical way of thinking, than languages like Java, which teach you to hunt for the nearest library. "Oh my boss told me to make a First Person Shooter 3D game, where is the makeFPSGame(TYPE_3D); function and where is the Game API"
Java gives you stuff to have a lazy stroll through a project but bloats things up. There's not much fun doing it.
Simple efficient code is the best solution in most of the cases. Machines love language that they can understand and that is machine code. Each level up from that adds more nonsense to what it is being said.
Java has its uses too.
Those who ignore the past are condemned to repeat it, BADLY.
C++ application binaries are not portable, but source code is, if you are not stupid enough to use a lot of platform specific functions without trying to abstract them.
Your focusing on a slight performance gain (probably lost in browser to server latency anyhow) rather than productivity.
Lets take this blog for example, convert that into your next gen web app in C++, lets set a time limit say 24 hours. I don't think your get very far (compared to someone using a JIT'ed language) or you could prove me wrong of course :-)
It's nothing to do with the language, it's because Apple only allow Objective-C on the iPhone, because they are closed a source corporate machine - there are plenty of Java apps running on other mobile devices.
This approach allows you to deploy your applications on simpler hardware (cheaper to replace as well as buy in the first place) with savings in almost every area and less downtime. Whats not to like?
It depends on what you want. If you want to go fast to market you might want to go with Rails or similar and replace it with faster implementations on a need basis...
Anyway, there are no "right recipes", you always trade things off.
1. It great grandparent was a dos program written in C++.
2. It uses a lot of secret special sauce that my company wouldn't want to sell as a php script.
3. It is blazingly fast.
4. The same base code runs on pocket computers PCs and webservers, because if (carefully) written without using templates, C++ is portable!.
love the customer expectation part
i had written c++ web app long back
He is selling it.
www.squidoo.com/sqlitetutorial
www.squidoo.com/sqliteprogramming
www.squidoo.com/sqlitedatabaseprogramming
I also have videos on YouTube (just search for "sqlite tutorial" and look for my videos with the black command line screen.
man you made me laugh like never "The only disadvantage is that the final executable is really small".
I always had this problem, seriously! A friendly low-ranked client once told me : "what! you mean to tell me that we paid $60,000 dollars for for three cheap floppies!", are you out of your mind! give me five CDs and i dont care if you fill them with high resolutin pictures".
lolololololol.
Thanks for the superb article. mrfarhat@hotmail.com
Sorry I forgot to say "LONG LIVE C++", and "THERE IS ONLY ONE C++" as in "There is only one Ronaldo".
lolol
GPL only forces you to release the source code if you *distribute* the program.
With a server-side app, you don't ;)
Post comment