Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: What A Wonderful World: Bitmasks!

by jkahn (Friar)
on Dec 08, 2002 at 21:27 UTC ( #218397=note: print w/replies, xml ) Need Help??

in reply to What A Wonderful World: Bitmasks!

In addition to the excellent responses from chromatic, theorbtwo and dws, I'd like to point out one further potential problem.

I frequently find that it's valuable -- at least in initialization -- to have three values for my user parameters -- true, false, and undefined, so I can tell the difference between never set and false.

Bitmasks default to 0 (at least, that is the usual convention), and from inside my initializer, I can't tell whether the user neglected to set (e.g.) COW or if s/he explictly set !COW. So distinguishing undef in this three-valued system allows me to detect the neglect case and set a default or carp appropriately.

Hmm... on reflection, I wonder how many other languages provide this useful distinction? C certainly doesn't, and it's a recurring PITA in my work there. I find Perl's distinction in this domain (a built in trinary Boolean value, if you will) to be one of its truly endearing features.

Just my $0.02 US.

Replies are listed 'Best First'.
Re: Re: What A Wonderful World: Bitmasks!
by demerphq (Chancellor) on Dec 09, 2002 at 01:07 UTC
    I agree about the undef point. A similar idea is taking advantage of perls flexible parameter passing, such as checking to see how many args were passed.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://218397]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-01-20 09:28 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.