News for hackers. Stuff that matters.
Re:Common mistakes made by beginner Python programmers by tempguy9999 on Monday July 01, 2019 @04:57AM (#20323595)
> Boolean is a subclass of Integer, because... why?

truth/falsity is more general than that in python, so bools aren't really necessary.

As for why, 0 is false, nonzero is true (not 1, any non-zero). So false is 'nothing there' and true is 'something is there'. This generalises to other structures, an empty list is nothing (ie. false) a non-empty list is not-nothing so is true so you can do

  >>> y = [23, 24, 25]
  >>> while y:
  ...   print(y)
  ...   y = y[1:]
  ...
  [23, 24, 25]
  [24, 25]
  [25]
Ditto loadsa other things.

I guess this was a lisp inheritance.

Re:Common mistakes made by beginner Python programmers by hjk05 on Tuesday July 02, 2019 @04:03AM (#20333118)
> As for why, 0 is false, nonzero is true

It’s not that clear cut. If you assign d[True] and then d[1] you overwrite because True hashes to 1, not because 1 is a truthy value. If you try writing to d[2] you don’t overwrite d[True].

In any case this Feels like an odd case where python is sort of doing something similar to implicit type conversion which goes against the zen of python.

Re:Common mistakes made by beginner Python programmers by tempguy9999 on Tuesday July 02, 2019 @04:27AM (#20333243)
This is an excellent point, and one I met a while ago when designing a rather specialised DSL. I went the same way as python, so one didn't have to keep casting to bools to do a check and it made things a lot cleaner mostly, but it did introduce some dubious corner case niggles. I don't know if there is a good answer. I didn't find one anyway.