Skip to main content
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: ...
mousetail 'he-him''s user avatar
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 ...
IMSoP's user avatar
  • 2,667
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 ...
Michael Homer's user avatar
  • 13.6k
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 (...
user's user avatar
  • 912
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 ...
user's user avatar
  • 912
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 ...
Steve's user avatar
  • 778
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 ...
Silvio Mayolo's user avatar
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 ...
James Martin's user avatar
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 ...
abel1502's user avatar
  • 2,595
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. ...
chrisaycock's user avatar
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 ...
Olive's user avatar
  • 470
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 ...
tinlyx's user avatar
  • 447
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) } ...
Seggan's user avatar
  • 3,053
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 ...
ice1000's user avatar
  • 2,694
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 ...
tarzh's user avatar
  • 4,284
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/...
Ginger's user avatar
  • 2,649
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: ...
mousetail 'he-him''s user avatar
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 ...
Longinus's user avatar
  • 1,883
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 ...
Quassnoi's user avatar
  • 141
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, ...
André L F S Bacci's user avatar
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 ...
qwr's user avatar
  • 481
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 ...
Jim's user avatar
  • 131
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 ...
Greg Nisbet's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible