Operator Precedence/Boolean Logic

Steven D'Aprano steve at pearwood.info
Sun Jul 17 06:04:53 EDT 2016


On Sun, 17 Jul 2016 05:44 pm, Lawrence D’Oliveiro wrote:

> On Sunday, July 17, 2016 at 7:33:19 PM UTC+12, Chris Angelico wrote:
>> 1) REXX and, I think, Pascal: there are two specific values that may
>> be used in conditionals, and anything else is an error
> 
> Worth comparing how two different languages deal with strict enforcement
> of booleans: 

> * Modula-2 does it right: BOOL is a separate type which is 
> required for conditionals, but
>     + the ORD and VAL functions offer typesafe conversions to and from
>     integers, and 
>     + BOOL can be used as an array index type, just like any 
>     other enumerated type.

That's also the Pascal model, which is no surprise, since Modula-2 and
Pascal are both invented by the same person, Nicholas(?) Wirth.

I'll certainly agree that the Pascal/Modula-2 model for bools is a good
model. On balance, I think that I'd argue:

- in statically typed languages, I'd look for the Pascal model;
- in dynamically typed languages, I'd look for something that 
  matches Python's truthiness rules;
- or at least some other consistent, useful and simple metaphor 
  for truthiness;
- a mere collection of objects which happen to be arbitrarily 
  treated as truthy or falsey (like Ruby and Javascript?), 
  lacking any consistent metaphor, is in some ways the worst
  of both worlds.




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list