40
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
It's convenient for the way SQL is typically used. Consider this statements:
...
23
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
One way to look at this is to compare these two questions:
Is value A definitely the same as value B?
Is value A definitely different from value B?
On the face of it, these are symmetrical: if ...
22
votes
Accepted
What language was the first to treat null checks as smart casts to non-nullable types?
I don't think this design is as new as you're expecting, though practical languages designed from the beginning with this purpose in mind are more recent. For example, in 2002's Declaring and Checking ...
18
votes
What are the pros and cons of an Option type in comparison to nullable types?
Advantages of Option types:
No need to implement flow typing, which can be hard to get right
Can be used with primitive types (...
16
votes
Are there any benefits to an Option type in a dynamically-typed language?
Nesting
In a language with Options, you can have a function that takes a list of values and returns a new list with those same values wrapped in ...
12
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
I find it can be quite fiendish to explain this aspect of SQL convincingly, because of the sheer depth of an explanation which fully justifies the design and rebuts superficial objections. I don't ...
12
votes
What are the pros and cons of an Option type in comparison to nullable types?
Special-casing
Another factor to consider is how much of a special case your approach to nullability will require. Option almost never requires any special handling ...
9
votes
What are the pros and cons of an Option type in comparison to nullable types?
Option is an algebraic data type (ADT), so if your language already supports ADTs, you can implement Option in the standard ...
9
votes
Are there any benefits to an Option type in a dynamically-typed language?
Functional-style handling comes to mind. Even in your example, you have introduced a map method. This kind of API is very convenient for chained operations on ...
8
votes
Should a REPL show null values as null?
The REPL's output and input should be the same. I should be able to copy an output and paste it back to the prompt.
...
6
votes
Should a REPL show null values as null?
Many implementations of Scheme, among other Lisps, make a distinction between null (the constant value () which serves as both ...
6
votes
What are the pros and cons of an Option type in comparison to nullable types?
Monad
It should be noted that usage of option types can be simplified by using monad and other functional programming facilities, and they do not need to be unwrapped everywhere.
For example, if you ...
6
votes
What are the pros and cons of an Option type in comparison to nullable types?
Nullable types are at the same level of indirection
Suppose I have the following Kotlin code:
fun foo(): Bar? {...}
val x = foo()
if (x != null) {
doStuff(x)
}
...
6
votes
What are the pros and cons of an Option type in comparison to nullable types?
Apart from @user's answer, there's usually the following convention for nullable types:
a?.b()?.c()
This it is intuitive to translate the above into
...
5
votes
Accepted
Why isn't the nullable marker in Dart a monad?
This question has two possible meanings. The first is what prevents Dart's nullable marker from obeying the laws of monads?
The answer is that Dart's nullable marker isn't a monad because ...
5
votes
What are the pros and cons of an Option type in comparison to nullable types?
Operators
Usually, nullable types and Options will provide special operators, like the Elvis (?:), for checking if they're null/...
5
votes
Should a REPL show null values as null?
Output the value if and only if you have multiple nullish types. Python has only None so it doesn't print to avoid clutter:
...
5
votes
Accepted
How could I implement a non-null pointer qualifier in a C-style language?
Refinement Types
NonNull is a function of type (a: PointerType) → { n ∈ a | n ≠ NULL }.
Refinement types are types whose ...
4
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
For booleans, NULL means "the whole Boolean domain", or the set {true, false}
In SQL, the expression TRUE OR NULL is true (not a null, as some might ...
4
votes
Are there any benefits to an Option type in a dynamically-typed language?
Union types
Some languages never implement an Option type because they can express "one level" Option at syntax level, ...
3
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
Most programming languages implement Boolean, or 2-valued logic, with the familiar TRUE and FALSE. SQL implements a 3-valued logic with TRUE, FALSE, and UNKNOWN. In most SQL DBs, NULLs are treated in ...
3
votes
Why does SQL treat null = null as null, unlike all other mainstream programming languages where null = null is true?
Simply put, in the world of SQL, NULL means that the value is unknown. It can mean that the value simply doesn't exist, like it does in other languages. But, since ...
2
votes
Are there any benefits to an Option type in a dynamically-typed language?
As a quick remark, dynamically typed languages can still benefit from algebraic-data-type-like constructions in general (for example Prolog and Erlang) for writing correct code (even if the benefits ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
nullability × 7optionals × 2
language-comparison × 1
semantics × 1
type-inference × 1
dynamic-typing × 1
undefined-behavior × 1
repl × 1
history × 1
monads × 1