Sujet : Re: “Booleans Considered Harmful”
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.programmingDate : 23. May 2025, 23:58:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <100quit$a8a5$2@dont-email.me>
References : 1 2
User-Agent : Pan/0.162 (Pokrosvk)
On Fri, 23 May 2025 16:56:55 +0700, JJ wrote:
I don't think he's a versatile programmer, if he expect every code to be
self explanatory at any point.
His idea of “self-explanatory” seems to be the limiting factor. No
doubt he would throw up his hands in horror at any mention of De
Morgan’s theorems, for example.
Compare the boolean condition here:
def colour_samples(self, to_rgb, from_rgb) :
if (
not isinstance(to_rgb, (list, tuple))
or
not isinstance(from_rgb, (list, tuple))
or
len(to_rgb) != len(from_rgb)
or
len(to_rgb) % 3 != 0
or
len(to_rgb) == 0
) :
raise TypeError("args must be arrays of equal nonzero size, being a multiple of 3")
#end if
self.nr_colour_samples = len(to_rgb) // 3
self._write_stmt("ColorSamples", [conv_num_array.conv(self._parent, to_rgb), conv_num_array.conv(self._parent, from_rgb)], {})
return \
self
#end colour_samples
Would you prefer it written this way?
def colour_samples(self, to_rgb, from_rgb) :
if (
isinstance(to_rgb, (list, tuple))
and
isinstance(from_rgb, (list, tuple))
and
len(to_rgb) == len(from_rgb)
and
len(to_rgb) % 3 == 0
and
len(to_rgb) != 0
) :
self.nr_colour_samples = len(to_rgb) // 3
self._write_stmt("ColorSamples", [conv_num_array.conv(self._parent, to_rgb), conv_num_array.conv(self._parent, from_rgb)], {})
else :
raise TypeError("args must be arrays of equal nonzero size, being a multiple of 3")
#end if
return \
self
#end colour_samples