18
$\begingroup$
Javascript for example has both null and undefined values. They are nearly equivalent: both are falsy values that denote absence of data, the only difference is apparently whether or not it was "intentional". Uninitialized variables contain undefined but the developer could explicitly set them to null to denote that it was intentional and not a mistake.
Is this useful? Is this a good idea for a dynamic language? Or is it enough to have just null?
language-designtypesnullabilitydynamic-typing
Share
Follow
asked 2 days ago
Matheus MoreiraMatheus Moreira
47122 silver badges1212 bronze badges
$\endgroup$
12
1
$\begingroup$
FWIW, I suspect that null was added to Javascript to satisfy the bosses who wanted it to be more like Java. The language lets programmers write x - y without caring whether y is a number or a numeric string, so it seems implausible the design intention was for programmers to care about something much subtler.
$\endgroup$
– kaya3
Commented
2 days ago
$\begingroup$
And FWIW, SQL has null, which sometimes means missing and not applicable, and other times means missing though applicable. The former is meant to suggest that the type of a row is different, as happens when you have a table of employees with a column referring to their manager, since the CEO doesn't have a manager, then her manager is null, there meaning missing an not applicable. Whereas the latter usage of null means merely we didn't collect that information (like phone number or address). So, there's two usages of null yet there's no way of dynamically distinguishing between the them.
$\endgroup$
– Erik Eidt
Commented
2 days ago
$\begingroup$
In addition, NULL is also used in SQL to mean an empty/nothing value, i.e. the value is not missing, and it would be valid for a non-empty value to exist there, but the value happens to be empty/nothing. For example, a "products" table with a column holding an optional foreign key into the "discount codes" table could have NULL meaning that this product happens to have no discount code.
$\endgroup$
– kaya3
Commented
2 days ago
1
$\begingroup$
See three-valued logics and four-valued logics.
$\endgroup$
– shea
Commented
yesterday
1
$\begingroup$
I feel like the general rule is: if you see it in JavaScript and not elsewhere it was probably a bad idea. JS is a very poorly designed language.
$\endgroup$
– Jack Aidley
Commented
yesterday
|
Show 7 more comments