Truthiness

From Esolang
(Redirected from Falsiness)
Jump to navigation Jump to search

Truthiness and falsiness are mutually exclusive qualities that a value can have. By definition, the boolean value true will be truthy, whereas false is falsy. Truthiness (and falsiness) are used for conversion to booleans, especially for implicitly converting to booleans for commands that require them.

In Python, 0, False, "" and empty collections are all falsy, and most other values are truthy, which allows all values to be used as an if statement condition.

if "a":
    "This branch will run"
if "":
    "This branch will not run"

In other languages, truthiness is not defined for most data types. For instance, in Haskell, only the booleans True and False can be used in if expressions.

a = if True then "This string will be returned" else "This string will be ignored"

In some languages, truthiness is not defined for any data type. For example, in ///, building the truthiness oneself is the way of writing conditionals.

The Nature of Truth and The Nature of Truthiness

Truthiness and truth are related concepts, but not the same. The dictionary definition of 'truthy' means something that feels true, whether or not it is. Likewise, a value can be truthy if a program believes it to be true, regardless of whether it is true or not. Outside of logic programming and mathematical proofs, truth is less important than truthiness in programming. To put it another way, a programmer tells her program what to do and think, and should be able to tell it to believe anything is true/truthy, regardless of whether it is really true. In the subjectivity of an algorithm, malleable truthiness supplants the absolutes of truth and falseness.

"True" has two distinct uses. It describes statements that match the real world, which aren't truthy in a program that lies to itself. It also describes provable mathematical facts. The latter, information that can be deduced a priori, is truthy in most programs. For example, 1 < 2 is predominantly a truthy statement, but programming.IsFun() could go either way based on what the programmer decides.

Truth is a bit of a snafu, so if you want a definition, a more encyclopedic wiki would be better.

Non-Boolean Truthiness

Some languages, especially probabilistic ones, allow shades between true and false. The standard boolean operators, NOT, AND, OR etc, can be adapted to work on a probability between one and zero, instead of just 1 or 0. In fact, many systems of probability dispense with 1 and 0 on the Bayesian premise that nothing is ever certain, so no probability can ever reach either absolute. This fuzzy logic is common in neural network programs that operate on Bayesian principles.