[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Features you would like to see
- From: David Given <dg@...>
- Date: Fri, 17 Aug 2007 14:07:05 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Patrick Donnelly wrote:
> What features would you like to see added?
I'd like a goto.
The whole goto-considered-harmful myth has done the world a vast disservice.
goto is *entirely* the right construct for dealing with certain software
problems: for example, state machines. (And, in fact, Dijkstra was completely
up front about this in his original paper.) They're also very handy for doing
things like cleanup on error:
if not function1() then
if not function2() then
if not function3() then
The alternative approach is to use lots of nested if statements, which can
quickly get out of control if your logic is at all complicated --- and if you
need an exit strategy from within, say, a loop, you're basically stuffed. You
have to either duplicate code or use flag variables.
(They can also be trivially used for 'continue' and multi-level 'break'.)
...and while I'm whinging, it would also be nice to have some
try/catch/finally/throw syntactic sugar around pcall and error. I know it's
Not The Lua Way to provide high-level functionality like that, but exceptions
are so useful, and doing them yourself with pcall is so wordy, that I reckon
it's worth doing in this case.
┌── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ─── http://www.cowlark.com ───────────────────
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----