Thanks for the feedback and taking your time to challenge my point of view
In principle all of the features could be implemented, however, at the currently state more or less every derived method from the basic monad methods is to my knowledge not directly present. As far as I can see, Iād need to do some rewiring to call foo.map(something)
on a T?
- correct me if Iām wrong
[quote=āWasabi375, post:19, topic:2455ā]Ok you donāt like the syntax, that is however no argument against nullable types in kotlin. Also the kotlin syntax is quite consistent. Every time you see a ?
you deal with nullable types.
[/quote]
list.map(something)
stream.map(something)
is not consistent with:
if (nullable != null) { something(nullable) }
I could of course make something
take a nullable, but then Iād still end up with:
something(nullable).?....
which is still inconsistent. Similar for flatMap
. So yes Kotlin is in general consistent, however, this specific design is not consistent with the normal method calls of Monads.
It might surprise you, but for many people those functions are not well known or understood. They come from a functional programming background which only lately became more popular again so unless you have a background in those you wouldnāt know them.
Hmm, Iād have though people got used to it by now, after all we had in since Java 8, C# had it for even longer, and similar is also present in JavaScript. That said, if you are right, Iām inclined to argue that this stresses the importance if not introducing extra notations for the same thing. If things are not well understood, having multiple notations are not going to help.
[quote=āWasabi375, post:19, topic:2455ā]How so? Kotlin has checks at the beginning of all public functions to ensure nullability is not broken by java and in the java world you have to check for null in any case. The only thing to ask for is to return Optional
for those java libs/programs that use them but that is not always the case.
[/quote]
Breaks might be the wrong word. But the second Java code is involved then returning a null introduces the same hell that weāve been dealing with since the invention of the null, hence the opposition towards nulls and the experience that nulls are bad.
What does
Option.None
mean?
That there is nothing in the Option. Unless misused the meaning should be fairly clear. The meaning of null is not clear, in some frameworks it means that a query to a database returned no entries (should have been empty list perhaps), in some itās an error case, in some it leaked from somewhere and the meaning is garbled except itās a clear error. Also one could argue that Option is a special case list with 1 or 0 elements, where the 0 element list is denoted by a separate value, still a clear definition to me at least.
How would you use that typealias? What is the benefit of it? I canāt think of a single situation where this is actually required
Making the specific meaning even more clear. Required? No. But replacing booleans with meaningful enums are not required either, however it is often a good design. E.g., printJson(true)
vs printJson(JsonFormat.PRETTY)
should make it quite clear what the value of making ones names more explicit in the intent.
The type of null is
Nothing?
.Nothing
is the so called Bottom Type.Nothing?
is the nullable version of this and has the single value ofnull
.
Running out of time, but will take a look Seems interesting
[ā¦] You canāt guarantee it with optionals. [ā¦] Both java and kotlin are restricted by the JVM and the JVM has null. There is no way around that. [ā¦]
Switching language is not an option in my case, and not my purpose. Iām not saying Kotlin is bad, in fact I love it. What Iām trying to challenge is the idea that because we got nullable types means that we should throw out all of our experience gained through the last 40 years or so. Even though we encapsulate null and deal with the worst of it, we are still not safe. It is entirely true we arenāt either even if we follow the Optional pattern and wrap our nulls in classes (e.g., serialization frameworks can still ruin this). Iād still argue that we make it much harder to accidentally introduce an error, if we try to avoid nulls. This standpoint might be up for review, for instance pending on the nice links provided.
Btw a language without null but with Optionals just renamed the concept of null. On a theoretical system they end up being just the same. The only thing Optionals provide that javas nulls donāt is some amount of safety, but this is also provided by kotlins nulls.
Seems to be the point of one of the links provided by @arocnies. Canāt read it right now, but looking forward to it