Interesting thing about boolean in most languages is that it is often a trinary/tri-state variable, not a dual state true or false variable, reason being you often have nil/null you can set a boolean too as well and in many languages, particularly those where all variables are by reference, you cant change this.

Ruby is particularly interesting because it makes a distinct separation between a variable being not-set and null/nil. Therefore a boolean in Ruby is a quad-state variable that can be either not-set, nil/nill, true, or false.

NOTE: My comment about Ruby is actually misleading since its a dynamic language. If you have a variable intending to act like a boolean, strictly speaking, before you set it with a boolean variable it doesnt have a boolean type. So the boolean **type** is not quad-value. Its just any variable that the variable you intend to use exclusively for boolean can have any of 4 states, and likely does in most implementations.

@Science

Follow

@freemo Huh, neat. So, the tri-state ones, is null the same thing as not-set then?

@trinsec I'd be reluctant to generalize for **all** languages. But for all the ones I can think of you either need to explicitly set qa stating value, in which case people use nil to represent not-set as it is the only allowed value (this doesnt count things like haskell where they dont use a nil).... Or all variables implicitly and by default start as nil even if you didnt set it as such or at all (like in java)

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.