Cleaning up after yourself, prologue.
Errors that happen during onCleanup are transformed into warnings? Really?
It doesn’t help that cleanup functions also can’t be closures — they can’t actually respond to data about a resource that was gathered during a program. But first things first.
Hey: if an error happens in my code, that is an error. My program should not continue unless it specifically handles that error. If an error happens while my program is trying to clean up after itself, that means something is wrong and MATLAB should not force my program to blithely continue and wreak further havoc.
I’ve restrained myself from picking too hard on The Mathworks’ decision to promise deterministic destruction for closures and objects, even though it has unacceptable performance penalties. The reason for the restraint is that I can see the argument for object lifecycle management: when your objects correspond to exclusive resources you hold, you do want to have control and guarantees over when they get released.
Well, I just looked into onCleanup and as usual, the Mathworks fucked it up: You cannot write robust programs using onCleanup, because exceptions during cleanup are swallowed.
So I’m going to have to start kicking at the thirty misfeature pileup where MATLAB’s memory management meets its error handling, after all.
There are a number of languages that offer both automatic memory management and exceptions. A few of them are Python, R, Java, and MATLAB. All of these except MATLAB deal with resource cleanup easily with a try/finally statement, which MATLAB lacks, and most also offer some extra sugar in the form of a try-with-resource, which MATLAB tries to do with deterministic destructors, and fails.
One of these things is not like the others:
propagating the original error), it can do so.”
One of these things is not like the others, and the one that fucked up is of course MATLAB.
Emily Weir said,
April 23, 2012 at 3:55 am
Some of the warnings it throws up seem to make no sense too.
I’m writing a program to move from one configuration to another in a configuration space, and I keep getting:
“Warning: the value assigned to variable ‘initialconfig’ might be unused”
…Two lines later I use it, and it’s used many times throughout the program. It’s baffling.