On 11-06-08 01:27 PM, Ovod-Everett, Toby wrote:
Good point. It may, however, make the constants a bit confusing since some of them would have to be declared as negatives. For instance, in that world, wxTAB_TRAVERSAL would have to be renamed wxNO_TAB_TRAVERSAL. If you had an object with TAB_TRAVERSAL turned off and wanted to turn it back on, you would have to clear wxNO_TAB_TRAVERSAL, which is suspiciously like a double-negative. At the end of the day, this is one reason I think bitmasks aren't a particularly good interface. They're efficient, but they aren't actually very programmer friendly. Which is something else to remember when writing your own code! Avoid bitmasks as the interface for groups of binary settings! At one point I wrote Data::BitMask because I wanted a friendlier interface to bitmasks, but even it is really just a kludge over the underlying issue. I won't claim to know what the preferred interface is (a hash or dictionary?), and it may vary from situation to situation.
They're only efficient in terms of memory usage. On modern computers, it's often faster to access a 64-bit word than one bit of it. And on modern computers, memory usage is not much of an issue, either.
Unless, course, you're on a server, but then, you shouldn't be running a GUI on a server if you're concern about memory usage. :)
-- Just my 0.00000002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early & often. Eliminate software piracy: use only FLOSS.