Undefined is very underappreciated invention. I wish I had undefined in Java, throwing exception on read. That would make a lot of software much more reliable. I'm going to write my own AutoValue library just to generate java beans which will allow uninitialized values.
PS undefined in JavaScript is not that useful IMO. But it could be useful with more strict language.
Optional was added in java 8.
Re:Null Values in SQL Queries
by giornogiovanna on Monday February 03, 2020 @10:42AM
(#22225092)
Just to be clear, undefined is not valid in JSON. The only types in JSON are nulls, strings, numbers, arrays, booleans and objects.
"undefined" in this context means that the JSON object has had the relevant key omitted rather than explicitly set to null. This is valid JSON (it just so happens that JavaScript handles this scenario by returning "undefined" as with all undefined variables).
Re:Null Values in SQL Queries
by giornogiovanna on Monday February 03, 2020 @11:52AM
(#22225975)
Ah, right, my bad.
In my defense, JavaScript treats a value of `undefined` differently from an unset field / variable (e.g. when testing `object.hasOwnProperty('field')`).
JavaScript has too many "non-visible" value types in my opinion. This makes for both messy code and messy debugging.
Yes omitted value vs provided with null which is easy to work with in JS because of null and undefined and them being falsey.
Working with xml or json in more typed language like C# is less fun because there is not distinction in the language instead you end up using dom like checks to see if the key was provided or was set to null.
.Net code generator use to add an extra property called [property name]Specified for xml serialization so you could do null values or not send the node. Definitely prefer more direct language support for no value provided vs a null value.
Emtpy string vs null is not that useful if you have null and undefined.