Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: crafting a decent CLI

by Abigail (Deacon)
on Jul 13, 2001 at 11:49 UTC ( #96315=note: print w/replies, xml ) Need Help??

in reply to (tye)Re2: crafting a decent CLI
in thread crafting a decent CLI

Actually, you don't have to parse the rest of the do block to figure out what is going on. Once you see ";\ndo {\n" you know (from the ";" and newlines) that it isn't a (sensible) conversion of a block to an expression and (from the "{") that it isn't "do file".
I do not quite agree with that. You do know the expression modifiers, don't you? EXPR if EXPR and EXPR for EXPR etc are quite common in Perl. Every now and then you want to do two or more things in the first expression. EXPR, EXPR if EXPR sometimes works, but sometimes it won't. So you use do {EXPR; EXPR} if EXPR. That do is followed by a '{' and typically preceeded by a ";\n". And hopefully you aren't giving special meaning to the newline. ;-)

-- Abigail

Replies are listed 'Best First'.
(tye)Re3: crafting a decent CLI
by tye (Sage) on Jul 13, 2001 at 18:42 UTC

    That is what if( EXPR ) { EXPR; EXPR } is for. So, no, I don't consider that a sensible use of do.

            - tye (but my friends call me "Tye")
      The point isn't that you find it sensible or not. The point was how easy it was for others to parse your code. You weren't assuming I had to parse the bare block I wrote to see whether it's used as a multi-pass loop, do you? I wrote it, so I know.

      If you want to get into style discussions, that's fine, but don't come with arguments "oh, I don't find it sensible so don't apply my arguments on my code".

      -- Abigail

        I'm pretty sure I've never seen "do { ... } if ...;" or similar. That is so pointlessly obfuscated that it is something I would avoid (such as in a coding standard) even more than I would avoid bare blocks as loops (which I also find can always be replaced with better alternatives). So I still jump to "loop" when I see ";\ndo {\n" and I will continue to. I also still don't jump to "loop" when I see a lone open bracket (and nobody should since most of the time they'd be wrong anyway).

        So a do loop is clearer than a bare block "loop". True, there is no guarantee against somebody writing something that clearly looks like a loop but is in fact an unclear and uselessly obfuscated non-loop. That isn't a concern when trying to decide how to make code easy to maintain. If you've got "do { ... } if ...;" in your code, then you've got worse problems to deal with first.

        - tye        

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2021-04-15 00:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found