Re: [RFC] export TRUE and FALSE from someplace



On Tue, 2004-01-20 at 18:49, Jens Luedicke wrote:
scott asofyet org wrote:
i have grown very annoyed of needing to add

  use constant TRUE => 1;
  use constant FALSE => 0;

atop every gtk2-perl program i write.  [..]

Hmm. I'm using 1 and 0 for TRUE and FALSE.
Is there a special need for those constants?

the logic behind using them is that it make the code much more readable.
a good example is pack_start:

$vbox->pack_start ($widget, 1, 1, 0);

is (arguably) less clear than

$vbox->pack_start ($widget, TRUE, TRUE, 0);

in that it's obvious that you're not putting sizes in there, that
they're booleans. other functions have similar advantages,
$widget->set_sensitive (TRUE) is better than $widget->set_senstitive (1)
b/c it's clear that it's on or off, maybe it's something that you can
set how sensitive it is, and TRUE/FALSE shows that's not the case. it's
not a big deal. using 0/1 aren't wrong by any means, it can just make
for clearer code.

-rm




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]