Earlier quoted context omitted.
I'm going to be a bit pedantic here: There is a semantic difference between Option > and Option . If I intend to retrieve a setting from a file, the former allows me to differentiate between a missing file or a missing setting, while the latter destroys that information. i.e.: There are 3 possible cases, while only 2 can be represented. So T? doesn't compose, while Option does, which I'd consider a big difference. Ho…
> There is a semantic difference between Option > and Option . If I intend to retrieve a setting from a file, the former allows me to differentiate between a missing file or a missing setting Does nesting Option's really has practical use or does it quickly become confusing? In your example, Option > return type doesn't tell me by itself that this differentiates between a missing file or a missing setting. I would ne…
What if null was an Object in Java?
111–120 of 164 posts
Re: What if null was an Object in Java?
#112Has anyone tried to make null as a function? In Julia, there is a `get(null::Function, collection, key)` method which can be used in a syntax: value = get(collection, key) do error(“$key in the collection not found”) end This syntax has captivated my attention lately as it seems like a viable alternative to doing an explicit null check before using the value.
Actually using this instead of nulls in any sort of general case would be using CPS for all faillible APIs, and that sounds heinous.
Re: What if null was an Object in Java?
#113Java Optional std lib class, instead of a language (typesystem level) feature was one of biggest mistakes in its recent history.
Re: What if null was an Object in Java?
#114The only real problem with null, is not having a real optional type in Java. If you have it, 99,999% of null errors go away. Java Optional std lib class, instead of a language (typesystem level) feature was one of biggest mistakes in its recent history.
Re: What if null was an Object in Java?
#115Ruby has a `NilClass` and the best/worst part of it is the to_s is "", to_i is 0, to_f is 0.0, to_a is [], to_h is {} It's incredibly clean and convenient until you wake up one morning and have no idea what is happening in your code
Re: What if null was an Object in Java?
#116I think the nullable reference type system in c# is a perfectly workable compromise for languages that had nullability from the very beginning. Once a code base uses them fully, most null-related bugs are gone. And it’s far from an unwieldy bolt-on.
It's funny because I really dislike the C# approach. It's not truly enforced - any code with nullable disabled can call public functions with `null`, even if on your side they were marked as non-null.
Re: What if null was an Object in Java?
#117You can actually write extension functions for nullable types and calling them on a null value does not cause a Nullpointer exception. This also works with Java classes.
For example, there's a CharSequence?.isNullOrBlank(): Boolean function in the Kotlin standard library that allows you to implement a null or blank check on strings. There's a similar isNullOrEmpty function on Lists (and yes, this does work for nullable generic types too).
There are many good reasons to switch from Java to Kotlin. But this is probably one of the bigger ones and genuinely low hanging fruit. Made me feel stupid after years of dealing with Java NPEs routinely and writing a lot of very verbose and needlessly defensive Java code in attempts to avoid them. All that cruft goes away with a proper language. Other languages that do this too are available of course. Pick one. Any one that isn't Java. Dealing with this stuff in 2024 is stupid.
Re: What if null was an Object in Java?
#118I like the way null is handled in Java, I think it’s pretty well thought out, other than the small awkwardness with basic types. Contrast that with SQL, which had my external scorn for null != null So you can do WHERE table.col = Null…. Ugh
For anyone not familiar, or who doesn't know the reason null behave like this in SQL: in this word, null essentially means "don't know". So you can't assume a = b when a and b are null. They could be different values, just that we don't have them.
This thing being called null, where null has another semantic in the languages from which we send SQL request is confusing, and I suspect many of us would prefer null behave the same way as everywhere else.
Re: What if null was an Object in Java?
#119Earlier quoted context omitted.
The problem is, not all of these languages think that "" and null are equal.
I might choose to rephrase that as "the problem is, some of these languages think that "" and null are equal." :-)
Re: What if null was an Object in Java?
#120I think the nullable reference type system in c# is a perfectly workable compromise for languages that had nullability from the very beginning. Once a code base uses them fully, most null-related bugs are gone. And it’s far from an unwieldy bolt-on.