PEP 285: Adding a bool type

Ralph Corderoy ralph at inputplus.demon.co.uk
Mon Apr 8 06:54:29 EDT 2002


Hi Bengt,

> You could write
> 
>       a = b + oneIfMovableZeroIfNot(c)
> 
> if you wanted to be conspicuously clear about your function's intent.

is_movable is clear.  one_if_movable_zero_if_not isn't since I have two
phrases to parse, and a too-long name.  And at the end I'd just think,
`Oh, is_movable in other words.'

> It would express the semantics better if these were true boolean
> functions returning True or False, and you wrote it as
> 
>     major = [can_be_moved(o), can_be_sized(o), can_be_stacked(o),
>              can_be_coloured(o), can_be_hidden(o) ].count(True)

I'd just dislike building an array and then grepping through it for no
good reason, IMHO, when a simple addition suffices.

> Personally, I prefer to read unambigous code, and not have to refer
> to supporting documentation that I may have to double check anyway by
> reading function source, if I'm doing a serious review, e.g., chasing
> a bug. The new bools will help, since the arithmetic values can only
> be 0 or 1, and that is unambigous where integer function return
> values are not.

I don't see how your `count' version above means you don't have to
either believe the documentation of the five functions, or, better,
examine their code.  It's clear the code is counting those that return
True.  But they may be returning absolutely anything, just as they may
be in mine when I add them together.

Cheers,


Ralph.




More information about the Python-list mailing list