Wednesday, June 4, 2008

MATLAB vs. C++? And the winner is….

….C++, of course! And, for the simple reason that MATLAB IS EVIL!

To all you pseudo-programmers, Simulink-flaunting ‘engineers’ and the like who swear by the ‘inbuilt functionality’ and ‘user-friendliness’ of MATLAB, I would just like to say… people, get a life! Its not that you don’t KNOW how stupid this application is- after all, you are the ones who sit there wiggling your toes while MATLAB takes minutes to run something C++ would do in micro-seconds; and you are the ones who get stymied, trying to make MATLAB understand even most simple Data Structures - then why not accept it? Why not, for once and for all, agree to the fact that C++ is superior and stop going ya-ya-ya about the ‘cool’ things about MATLAB!

People often tell me that MATLAB works better for engineers because of its inbuilt libraries and as a proof (by demonstration) they may type ‘14382^11.32’ on their command windows and lo-and-behold MATLAB tells you the answer! And then their argument may go something to the effect that to do the same thing with C++, you would need to write a function, maybe include a couple of libraries, debug, compile and run … too much headache for something MATLAB does in ONE line! Well, that is a fair argument…. only if you think that that is engineering… namely calculating random numbers to the power of random numbers…!

Honestly, that is anything but engineering! Engineering is about conceptualizing and it takes power to design elegant structures to translate those concepts to code… A good data structure is the difference between an understandable, well-organized, effectual program and useless, exasperating gobbledygook. But that is something MATLAB just does not understand. The ‘arrays’, ‘cell arrays’ and ‘structure’ that it provides address the problem of stucturing data with the same success rate as Bush is addressing the issue of ending the Iraq War!

Engineering also needs checks and while I admit that C/C++ has its own shortcomings when it comes to security issues (memory leaks, garbage collection problems, etc.), MATLAB is just outright scary. For example, there are no type-checks as a variable can be redefined from an integer to a character, to an array, to a structure within the span of a single function! Further, MATLAB passes parameters only by value… which is totally sinful if you want to pass large arrays and structures… just think of how much time and space you are consuming!

With C++ and a little more patience you can write code that is not only more efficient, it also better structured, more-understandable at any later date and therefore more reusable… I guess that’s why the latest (2008a) version of MATLAB had introduced object-oriented concepts and parameter passing by reference… But that’s something I am yet to get my hands dirty with….