lua-users home
lua-l archive

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

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;

    tok = gettoken();
    if (tok == END)
        return ACCEPT;
    if (shift(tok))
        goto reading;
    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.)

- --
┌── ─── ───────────────────
│ "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
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla -