logoalt Hacker News

neillyonsyesterday at 10:55 PM2 repliesview on HN

I remember reading that in early versions of Python there was no built in True and False. Each user would implement this themselves as

True = 1

False = 0

then later these got added to the language. In Python 2 you could still reassign and swap them so that 'if False' was actually true!

True, False = False, True

Python 3 you could no longer reassign them.


Replies

Animatsyesterday at 11:31 PM

Misery is trying to retrofit "bool", True/False, and nil/null to a language. C had to do that. Python had to do that. Getting those wrong is one of the classic language design mistakes. It seems like treating "True" as a value that equates to 1 will work, but then the special cases get you. Like being able to perform arithmetic on True.

Common language design boners:

- Not building in strings. That's now in the past. Everybody has strings. (Well, C...)

- Not building in multidimensional arrays of the numeric types. Everything that number-crunches needs them, and having multiple definitions is Not Fun and may lead to expensive re-copying between different libraries. This is an enormous blind spot in language design. It's one of the reasons FORTRAN, which has good multidimensional numeric arrays, is still often used for number-crunching.

- Not standardizing the small vectors (vec2, vec3, vec4) and their matrix friends. Graphics code depends on these, and it's really annoying if there are multiple slightly incompatible implementations. Especially since GPUs have hardware for those types, and you want CPU and GPU to use the same representations.

- Not having arrays of bits. Pascal had PACKED ARRAY[0..N] of BOOLEAN but that was lost in later languages. It's useful to have that as a language construct, because most modern CPUs have good hardware for dealing with bit strings, and you'd like the compiler to use it.

Most useful languages acquire these features, but, when they come in late, there are multiple similar implementations, and libraries made incompatible by depending on different implementations.

(Amusingly, when Second Life switched from Linden Scripting Language to Luau, they initially had True, TRUE, and true all in use, as different types with different semantics. I was able to persuade the devs to unify the boolean types.)

show 1 reply
LPisGoodyesterday at 11:05 PM

It is certainly the case that isinstance(True, int) returns True, even today.

show 1 reply