Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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.


Comment on Re: What A Wonderful World: Bitmasks!
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2015-07-31 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (277 votes), past polls