comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Hierarchical States Machines
Date: Wed, 28 Apr 2004 22:00:52 -0500
Date: 2004-04-28T22:00:52-05:00	[thread overview]
Message-ID: <25OdncWDToOY7Q3dRVn-hQ@megapath.net> (raw)
In-Reply-To: jrOdnQYzWKMxkQ3dRVn-hQ@comcast.com

"Robert I. Eachus" <rieachus@comcast.net> wrote in message
news:jrOdnQYzWKMxkQ3dRVn-hQ@comcast.com...
> Incidentally, as far as I know, or for that matter most Ada experts
> know, this is the only area in Ada where you should use gotos.  But goto
> has been kept in the language primarily because it is _necessary_ to
> create maintainable finite state machines, push-down automata, and the
like.

Ah, baloney. :-)

I use gotos whenever they prevent duplicating work that otherwise would have
to be done. It's silly to have two copies of code to do something just to
avoid a goto (or to make such code into a subprogram with no purpose other
than to avoid a goto).

A common case is to emulate the missing "continue" that Ada doesn't have. It
usually shows up in some deeply nested code:

    loop
        <bunch of conditions>
            <Do some processing>
            if <unusual condition> then
                  <Handle unusual case>
                  goto Continue;
           end if;
       <bunch of else conditions>
       end if;
       <normal processing>;
     <<continue>> null;
   end loop;

You can avoid the goto by making a hash out of the code, but why bother?
Gotos are efficient, not particularly unstructured in Ada (most of the bad
cases are illegal) - compiler optimizers are unlikely to be able to get rid
of batches of boolean flags and turn them into the branches that really were
intended in the first place.

                       Randy.






  reply	other threads:[~2004-04-29  3:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-28 18:48 Hierarchical States Machines Fabien
2004-04-28 19:39 ` Marius Amado Alves
2004-04-28 19:57 ` Robert I. Eachus
2004-04-29  3:00   ` Randy Brukardt [this message]
2004-04-29  7:25     ` Martin Krischik
2004-04-29 20:37       ` Randy Brukardt
2004-04-29 12:10   ` Wojtek Narczynski
2004-04-29  3:58 ` Steve
2004-04-29  5:14   ` Robert I. Eachus
2004-04-29  6:36     ` tmoran
2004-04-29 16:36       ` Robert I. Eachus
2004-04-29 15:41   ` Marius Amado Alves
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox