Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: block-based programming...

by tilly (Archbishop)
on Apr 22, 2004 at 21:35 UTC ( [id://347485]=note: print w/replies, xml ) Need Help??


in reply to block-based programming...

I have used a similar block-style before, so I'm going to say that it is sometimes justified. (Look for redo in the Carp::Heavy shipped in Perl 5.8.) I'd only think that it is justified if you have many conditions that you need to satisfy to leave the loop (my situation there) or else factor the code so that the odd flow of control is compactly presented in an understandable way.

In your case that would mean that you should make A, B, C, etc into functions (hopefully well-named ones) and then write the flow of control in a small block. like this:
EDIT_MAP: { attempt_edit($map); redo EDIT_MAP unless can_parse($map); redo EDIT_MAP unless user_confirms($map); attempt_edit($reverse_map); redo EDIT_MAP unless can_parse($reverse_map); redo EDIT_MAP unless user_confirms($reverse_map); } commit_edit($map, $reverse_map);
Now the key flow issues are put somewhere where the redo logic is very easy to understand and is not intertwined with the grungy details of the steps. It would be easier, for instance, for someone who didn't know the code or technique to look at this and figure out how to add a "give up" option on those redos, or to have F-H by default fail back to F rather than C.

(Yes, my experience suggests that if someone wants a change in this script, then they are quite likely to want to make them to the flow of control.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found