Wednesday, February 06, 2008

Application Level Programming in C++

C++ is a language that you could twist to almost any form of programming (with a cost, of course). You could program with low-level-ness that is only one step away from assembly language and on the other extreme you could build the huge common-user-centered application with all it's bells and whistles. Here I would like to elaborate about the later.

Now that we have Java and C#, it's hard not to think application-level programming without getting them into the discussion. Doing the same thing as C# code would then mandate the C++ programmer to at least review factors that makes them widely-adopted (and even better to try them deep enough to really "get" it) and take some lesson.

That being said, I think to be able to compete in application-level programming using C++ i.e: use C++ to get the performance and flexible lower level API but still able to avoid getting stuck and wasting time in micro problems (pointer anyone?), is to "emulate" the virtual machine e.g: JVM, .Net.

Clearly, what I mean by emulating is not to make another VM or code a scripting a language (most language written in C/C++ anyway). What I mean is to prepare the environment, libraries, framework, tools, build system, etc.. so that you only concern with matters that most people using language like Java is concern too with other thing handled by your manually-crafted VM. Those things should be assimilated, glued and setup with rigidness to the point that we can take them for granted to be working and the use of them is made semi-automatic in our daily typing/coding.

With existing components available now, you could already emulate almost what the Virtual Machine offer albeit with a little more hard work on your part. If you think the gain is worth it then many things already available to you.

For example, using naked new and delete can be considered suicide if your aim is to make an application (hint : boost::shared_ptr). Iterating collection using Functor or using old-style for (incrementing index) would make you hard to match readability of C# code (hint : boost::lambda). Manually editing Makefile if you aim to make big application could cripple your speed when something messed up with the makefile along the way or it become an unmaintainable monster (hint : CMake, Rake, Ant). There are already libraries and tools to help you match those kind of things that many other offer in VM-based language.

Just because you have to use C++ does not mean you can not use conceptualization, abstraction, modularization that is used by higher level languages and put them to good use in your own case and situation.

No comments: