Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Multi-stage flip-flop?

by sundialsvc4 (Abbot)
on Dec 11, 2014 at 13:56 UTC ( [id://1110043]=note: print w/replies, xml ) Need Help??


in reply to Multi-stage flip-flop?

On any code-review, I would give thumbs-up to the “state-machine driven” approach, and I always thumbs-down the use of Perl flip-flops.   They are one of the very few “IMHO, really bad ideas” in this language, although there is nothing to be done about them now (except to not use them).   At one time, they might have been seen as desirable because they let you feed a few fewer inches of paper-tape into your teletype machine, but to me they are extremely obtuse.   You cannot readily look at the statement and see what it is going to do, well, “next.”   Nor why.

The other approach, on the other hand, is both perfectly-clear to read, and easily maintainable.   First, the logic decides what to do next, based only upon what it sees and upon the value of variables whose values can easily be printed.   (There are no “side effects.”   It’s all right there in front of you.)   Then, separately, it carries out the appropriate action for that case.   What will the behavior be?   It’s clear.   How do I change it, and how to I demonstrate its new correctness?   Again, clear.   That’s the kind of code you want to be in your repository.

Replies are listed 'Best First'.
Re^2: Multi-stage flip-flop?
by RonW (Parson) on Dec 11, 2014 at 17:12 UTC

    Perl flip-flop seems to be a generalization of range matching like in awk, sed, SNOBOL and others.* (Generally "rule-action" languages.)

    I can see where the generalization may have gone too far, but in the context of regular expressions, syntax like:

    /match0/ .. /match1/

    seems clear to me. Or perhaps the awk/sed syntax:

    /match0/, /match1/

    might be clearer - except that it would be inconsistent with other uses of , in Perl.

    ---

    * I learned about SNOBOL long ago when I took a "300 level" CS class called "Language Stuctures". It was a very interesting class. Learned about several weird languages, including ProLog, LISP and APL.

Re^2: Multi-stage flip-flop?
by RonW (Parson) on Dec 11, 2014 at 18:34 UTC

    Relevant to sundialsvc4's comment "based only upon what it sees and upon the value of variables whose values can easily be printed", many textual state machine description syntaxes do not declare an explicit state variable.

    For example, in some dialects of Scheme, this:

    (define mystm (automaton init [init : (a -> slurp)] [slurp : (b -> done) (* -> slurp)] [done : success] ) )

    defines a state machine equivalent to a Perl flip-flop. ("success" resets the state machine and returns true to the parent task.)

    In cond0 .. cond1 the states are anonymous, but cond0 is the "event" instigating the transition from the initial "inactive" state to the "active" state and cond1 is the event instigating the transition back to "inactive".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1110043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found