On Saturday 24 September 2005 07:31, Glenn Maynard wrote: [...] > In some old OpenAL code, I found constructs like this nested fifteen (15) > levels deep--apparently whoever wrote that code had never heard of break, > continue or return. I know someone who writes code like that. The reason, however, is to make it easy to do cleanup: a = create() if a then b = create(a) if b then c = create(b) if c then d = create(c) if d then d:dosomething() d:destroy() end c:destroy() end b:destroy() end a:destroy() end I hate this, and tend to rewrite using gotos, but that's equally messy --- it just avoids silly indentation levels. The only 'right' way I know of of doing the above is to use exceptions --- which is very wordy, no matter what language --- or to leverage the garbage collector, which we can't do in our language. These days when writing C++ I use smart pointer abuse to hide the check-and-destroy statements. The resulting code isn't great for efficiency, however. I would *love* a continue statement in Lua --- I find myself wanting it frequently. For that matter, I'd rather like goto, as well, but I probably shouldn't admit that in public. -- +- David Given --McQ-+ "...thus there might be a great reduction in | dg@cowlark.com | useless expenditure on Nuclear rockets, reducing | (dg@tao-group.com) | inflation and stabilising the price of cat foods." +- www.cowlark.com --+ --- UK pat. GB1426698
Attachment:
pgp8DTFcuq2JH.pgp
Description: PGP signature