lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John Belmonte wrote:
> David Given wrote:
>> 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.
> 
> I thought coroutines were entirely the right construct for state machines.

Depends on the state machine.

For example (this is a classic example by David Tribble, not my own):

int parse()
{
    Token   tok;

reading:
    tok = gettoken();
    if (tok == END)
        return ACCEPT;
shifting:
    if (shift(tok))
        goto reading;
reducing:
    if (reduce(tok))
        goto shifting;
    return ERROR;
}

[...]
> Actually, neither goto or nested if's are readable, but fortunately
> these two are not the only solutions as you suggest.
[...]
> Yes, minus "finally".   try-finally as a solution for exception safety
> or resource cleanup is dead and best eschewed by modern languages.

That may or may not be true, based on what programming ideology you follow.
However, I'm a pragmatist. I want the tools to be available so that I, the
programmer, can make the decision whether to use them or not. So I want
try/catch/finally *and* scope(exit) primitives; they're both potentially
useful. I'll use whichever seems most appropriate to solve the problem at
hand. (I may decide to use neither and use a goto instead.)

- --
┌── dg@cowlark.com ─── 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

iD8DBQFGxy9Kf9E0noFvlzgRAhC2AJ9CmdHQukwXv76HlswMEQlSKaRX7wCgm3fK
Zl6DsJs7z540T2P+TNN4reo=
=84R9
-----END PGP SIGNATURE-----