Friday, December 10, 2004

Re: which is faster : C or C++?

I agree with Mohnish here. When comparing languages for implementing something you gotta see what suits the purpose best. The cost for virtual functions and polymorphism in C++ is a single virtual table pointer in each object and the resolution of those pointers and what exactly should be called based on the heirarchy of class implementation. But what you get for that is a whole new paradigm under your control. A whole new world view if you will. No more is programming based on thinking about what piece of information is processed when rather we are supplemented to talk in more abstract or high level terms.

A language which gives you the power to do object oriented programming at the cost of a single virtual table pointer is a piece of work in itself. Primarily what I love about C++ is the STL. It has never given me more pleasure to see a library in action. Granted that the organisation of the STL reflects the fact that there were multiple design heads involved but yet it's the most beautiful piece of code I have ever seen, if you don't agree just open up the algorithm or functional standard header and read for yourself, it's beautiful!! :) Whats even better about C++ is it doesn't force a programming paradigm on you, it lets you design your solution in any way you wish, so if you want to have a C style program, well just go right ahead!! Always remember that C++ was meant to be a better and "safer" C.

Over C, I'd choose C++ anyday, besides I hate writing the cumbersume printf() statements for everything, cout is so much better :) (ok, that was my cheesy joke for the day! sorry!!)

Put things in context and you'd see that C++ gives you a lot more than C, atleast thats what I think. One gripe I have with the g++ compiler is that it produces a lot of code, the -strip option does work well but still I have never been able to figure out what bloat code it writes! But then again with memory so cheap now it doesn't really matter.

By the way, can you factually prove that C++'s optimization is not as good as C(or were you saying something else)?? The g++ gives three levels of Optimization - O1, O2 and O3, all my programs are compiled with the -s -O3 options (releasable code that is). C++ by it's very design allows the compilers a lot of lee-way as to what it can optimize. And the GNU compilers sure do make use of it!

All in all whatever the speed comparisons, if I had a big project to work on, I'd be betting on C++ to get the job done in a good and maintainable way!


No comments: