Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: (jeffa) 2Re: (Ovid - Why I love nested If-Else blocks)

by dws (Chancellor)
on Jan 04, 2002 at 03:58 UTC ( #136151=note: print w/replies, xml ) Need Help??


in reply to Re: (jeffa) 2Re: (Ovid - Why I love nested If-Else blocks)
in thread Why I Hate Nested If-Else blocks

I might do something like this:
my $func = ($foo > 7) ? $bar && \&bar_mysub || $baz && \&baz_mysub : $bar && \&bar_other_mysub || $baz && \&baz_other_mysub; $func->($foo) if $func;
Don't align things vertically for the sake of aligning them, align them so that they're readable! The fragment above borders on obfuscation. There's a mind-numbing repetitive pattern on the right, and this
|| : ||
thing on the left. Yuch. I had to stop and really look at that fragment to get past the visual clutter.

Replies are listed 'Best First'.
(jeffa) 5Re: (Ovid - Why I love nested If-Else blocks)
by jeffa (Bishop) on Jan 04, 2002 at 04:30 UTC
    Awwww man, i like that ... thing:
    || : ||
    gave me an Atari flashback! :D

    I do commend runrig for giving a working piece of code that kicked the dog doo out of it's conterpart. It took me very little time to parse it, but i am not a newbie anymore.

    For a newbie - that's just got to look like a nightmare. I really think that this is why Ovid loves nested if-else blocks:

    Because newbies (especially those that are new to Perl but not to programming!) can understand them must faster.

    Me, i like the dispatch table - once you really start using them, it's hard not to. Point of little return, so to speak. For one thing, it is very scalable - adding two new conditions was very easy:

    my $func = ($foo > 7) ? $bar && \&bar_mysub || $baz && \&baz_mysub || $qux && \&qux_mysub : $bar && \&bar_other_mysub || $baz && \&baz_other_mysub || $qux && \&qux_other_mysub ; $func->($foo) if $func;
    I did move the '?' and the ';' to make it easier to cut-copy and paste it ... but, man have we gotten away from a simple solution:

    Tuck the check for the value of $foo away in the subroutines themselves, redundant, but that should be a piece of cake to follow and seems more configurable in the long run as well as very straight foward. The redundant pieces will end up becoming different anyway, thanks to Murphy's Law. ;)

    jeffa

    || : ||

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136151]
help
Chatterbox?
[Discipulus]: i propend for removing: why? because we are so few that we must find i minimal common divisor, this is certainly Perl not our (anyway private) thougths. And i say this still wondering because i love a lot freedom of expression. And i say this not for roho
[1nickt]: Discipulus that was the point of my story of taking the sticker off my truck. I know there are lots of people in the world who if I knw their private beliefs I might want to argue with them. And they with me. But life cannot all be arguments!
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious
[Discipulus]: you are right 1nickt i didnt voted nor downvoted; I just upvote perl content i like
[1nickt]: In Spanish, to argue (like a fight) is discutir -- does not mean to discuss !

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-06-22 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.