Tuesday, August 30, 2005

C++ and Java ...

I work at IBM Research on the WebFountain project. I pretty much do 95% of my programming work in C++. I consider myself a fairly decent C++ programmer. Nevertheless, every once in a while I run into these embarrassing moments, where I write a simple piece of code and lazily use an explicit cast and all of a sudden my simple program simply won't work. That's the reason why there is the C++ casting operators static_cast, dynamic_cast and const_cast. My advice is, that you should learn how to use them because they can save you a lot of time. Anyway, thankfully I found the problem myself after I asked my friend and co-worker Dan to take a look. But it was still embarrassing having to tell him that I f..... it up.
Which brings me to my next point, C++ and/or Java. That thing would have never happened in Java, since there aren't any pointers and you either geta compiler error for casting inappropriately or you get an exception during runtime. However, even though you have to be more careful in C++, I like it better because it gives you more control and programmers who start out in a language like C or C++ are generall the better programmers because they have to know the concepts of memory management.
I mean, why for crying out loud, does a simple instant messaging application written in Java have to have a memory footprint of 50MB or more (referring to an in-house IM client which is nice but a memory hog). I occasionally interview people for jobs here and come across students that only learned Java and never wrote a line of C or even Assembler. I think that's wrong because it teaches them to not worry about memory management because there is garbage collection. I know machines have more memory and get faster by the minute, but the way some programs are written these days, it looks like there will always be a programmer to fill the extra Gig of RAM.
The moral of the story is, to be careful when and how to cast, and C++ is still way cool.

No comments: