Search |
MATLAB Ranting, Part I: try-catch-statements done wrongI am currently trying to get MATLAB (a high-level language and interactive environment for computational problems) to work properly with some piece of visualizing hardware and ever so often I find small pieces of MATLAB terribly annoying, to say the least. Keep in mind that MATLAB is a tool with a very specific purpose. And in the scope of this purpose it works quite well. But as a programming language, MATLAB is bad. Very bad. Generic tasks are nearly unaccomplishable because of restrictions in the language obviously introduced for design decisions having a simple mind in - well - mind. I stumbled upon many those restrictions (and stumble is the right word here, trust me), and I planned on making one big 'Why MATLAB is a bad programming language' article but now I collected so many bads and no-noes and stuff that I could feed this blog for years alone with this that I decided to make a new series on this. Everyone knows try-catch-statements. Matlab has them, too.
The only problem is that user interrupts aren't catched by this block. So I made a research on the web. And I found some entries in forums regarding the clean-up problem. The most ridiculous solution I found was the notion that since destructors in MATLAB 8 are called every time, have your clean-up code in a dummy class sporting only such a destructor. But then, after much researching and teeth grinding, I finally found why Ctl-C isn't catched. To sum it up, all evidence points to it was a design decision. A design decision! So that those pesky catches won't end up in an endless loop! The example given on the page is the following:
Of course I can see how this would end up in an unescapeable loop. But my experience with C++ tells me that no catch statement should handle arbitrary errors ever. Exactly to prevent those things. So most decent programmers would have come up with something like this:
MATLAB is not designed with decent programmers in mind. MATLAB is designed for mathematicians and the like, people who don't want to think about things like that. And that's fine. But this makes it very hard for me to guarantee a safe state after cancellation. The script could always be cancelled via Ctrl-C and leave the system messed up with my path additions, my global variables, my open files, hardware, et cetera. I can call a cleanup function manually, sure, but this isn't how it should be. Long story short: Regardless what purposes as a tool it might serve, as a programming language MATLAB is one of the worst I have ever seen. And believe me, I have seen many. Thanks for tuning in,
|
Recent blog posts
DHReutter's del.icio.us links
|
Recent comments
4 days 3 hours ago
9 weeks 3 days ago
25 weeks 3 hours ago
44 weeks 2 days ago