Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Sutra of Optimism

by shirkdog_perl (Beadle)
on Nov 27, 2002 at 03:33 UTC ( #216000=poem: print w/replies, xml ) Need Help??

It is interesting, that your thinking in general can affect the code you produce. I am only a beginner at perl, however, I received light in this vision of Optimistic Expression through Perl.
#!/usr/bin/perl -w # # This dawned on me, that you can tell a persons # outlook on life, based upon the way they use their # Regular expressions. # ######################################### use strict; #philosophy my $answer = 555; # watch the mind of a pessimist, always thinking # negative. if ($answer !~ /\d+/) { print "Pessimist"; } # Now the optimist if ($answer =~ /\d\d\d/) { print "Optimist"; } print "\nTest your Perl monk friends, do they always think negative?\n +";

Replies are listed 'Best First'.
Re: Sutra of Optimism
by demerphq (Chancellor) on Nov 27, 2002 at 11:34 UTC
    Maybe im taking this too seriously but I dont think that your theory holds much water.

    Some tests need to be negative and some positive. The fact that an author has used one or the other is indicative of the needs of the code and not the psychology of the author. For insantce the two regexes you show are not interchangable, so psychology cannot have been responsible for choosing one or the other.

    --- demerphq
    my friends call me, usually because I'm late....

Re: Sutra of Optimism
by BUU (Prior) on Nov 27, 2002 at 06:52 UTC
    Wouldn't it make more sense to have an optimist be  /\d+/; and a pessimest /\d*/;?

      No because /\d*/ will always match so you must be significantly more optimistic about the state of your data than a more restrictive /\d+/. requiring at least /something/ is still pretty optimistic...

      __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;
      /\d*/ would be the apathist , I'll take digits if they're there, but whatever is fine by me..

      the optimist perhaps would not even consider using a regex, this scalar will always be a number.

      the pessimist ?

        the pessimist ?
        die "Pessimist";
        A true pessimist would not even bother to test for the numbers, because he *knows* in his heart that there will be none. ;-)
        You have moved into a dark place.
        It is pitch black. You are likely to be eaten by a grue.
Re: Sutra of Optimism
by belg4mit (Prior) on Nov 27, 2002 at 19:45 UTC
    Another failing is they aren't fully symmetrical. Typically once pits "the glass is half empty" against "the glass is half-full". You would need
    !~ /\d{3}/

    --
    I'm not belgian but I play one on TV.

      Interesting view points on the actual code. I just sometimes see myself testing conditions on whether they are false, rather then they are true
Beware the nihilist
by frankus (Priest) on Dec 09, 2002 at 11:43 UTC
    In your code if $answer were 5555 then the outcome would be nothing..
    print /\d\d\d/ ? "Optimist" : "Pessimist";

    This makes me more pessimistic but less nihilistic. Whether that is a good thing or not depends on whether you're a pessimist or not. ( And not as you may think ;^)

    I guess I try to catch all conditions simply because I am a pessimist and I've rather be pessimistic so the "hobbits"1 of the world can remain in their naive optimism.

    --

    Brother Frankus. 1) By Hobbits I mean the bright and cheery non-technical people of web sites who believe they'll not be hacked by remaing chipper and that the tech team will always pull their asses out of the fire, when they ignore advice ".. so why be dour?"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (1)
As of 2023-01-29 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?