[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Ah, those uninitiated people...
- From: David Given <dg@...>
- Date: Thu, 14 Jan 2010 01:25:34 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 13/01/10 19:34, Tony Finch wrote:
[...]
> But my point is that you can replace state transitions like this:
>
> goto newstate;
>
> with this:
>
> return newstate()
It's not the same, though. Apart from having to reorder my logic to suit
the restrictions of the language, which is always a pain, there's a
performance hit in that shared state has to be accessed via upvalues
rather than locals, which are considerably more expensive --- not just
to access, but also to create individual closures for each state in your
state machine. Say you have a state-machine based parser for network
packets. You have two choices: construct and then discard potentially
hundreds of closures for every packet, or restructure the entire state
machine not to need shared state. One's slow, the other's inconvenient.
You're all rather missing the point with goto, though. I'm not
suggesting that it's the best tool for any particular job. I'm saying
that it's the *only* tool that can do *everything*. It's the thing you
reach for when all else fails. If you find yourself needing goto, then
the elegant solution has failed; the only thing remaining is the messy
solution. I have no objection to goto being labelled with a large DO NOT
USE UNLESS YOU *REALLY* KNOW WHAT YOU'RE DOING message in the
documentation --- Ada did that --- but I do object to it being omitted
in some misguided attempt to improve my code... see signature!
- --
┌─── 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.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iD4DBQFLTnKOf9E0noFvlzgRAj/pAJiyWXSyCPh5SntnIf95I6hYtrrZAKDdvzI8
u0rpoV8UXdXRX1nprlKRQA==
=8VRL
-----END PGP SIGNATURE-----
- References:
- Ah, those uninitiated people..., Alexander Gladysh
- Re: Ah, those uninitiated people..., Enrico Colombini
- Re: Ah, those uninitiated people..., Roberto Ierusalimschy
- Re: Ah, those uninitiated people..., Andrew Wilson
- Re: Ah, those uninitiated people..., Mark Hamburg
- Re: Ah, those uninitiated people..., steve donovan
- Re: Ah, those uninitiated people..., David Given
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., Wesley Smith
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch
- Re: Ah, those uninitiated people..., David Kastrup
- Re: Ah, those uninitiated people..., Tony Finch