4 ms·
Mistyped, it's sealed interface. > So you can always have `Maybe<T> x = null`, or even `Some<T> x = null`. Yeah and? Practically every type system have escape
by gf000 4mo ago
Mistyped, it's sealed interface.
> So you can always have `Maybe<T> x = null`, or even `Some<T> x = null`.
Yeah and? Practically every type system have escape hatches, like Haskell can also do side effects without the IO monad, does it make the latter useless?
- tsimionescu 4mo agoThe whole point of using Optional/Maybe is to prevent the possibility of accidemtally creating nulls. If you don't make mistakes, then nullability is not a problem. If you do make mistakes, then a class that only helps when you don't make mistakes is basically useless. This also has significant impact for serialization/de serialization - a classic place where you get unexpected nulls, that Java Optional/Maybe don't help with at all.
- joe_mwangi 4mo agoSince they plan to have null-restricted types, then I don't see any issue.
- Dylan16807 4mo ago> plan to Well wasn't that the argument above, that the stuff they added so far isn't proper at least in part because they didn't fix that problem yet?
- joe_mwangi 4mo ago> yet But up the comment section, someone thinks they won't be there 'in the future'
- Dylan16807 4mo agoThe comment that says it won't be there in the near future? That's seems like a reasonable claim to me. And a promise to eventually fix a busted implementation doesn't undo it being busted for a significant amount of time.
- joe_mwangi 4mo agoBetter late than never.
- gf000 4mo agoDisagree. Types are both for the compiler, as well as for the developer. Maybe types are implicit documentation telling the developer that it is meaningful in the application that this field can have a None state. That's a huge code smell to ever set null to an Optional/Maybe and code reviews, linters, nullness analyzers all should/will flag such. Like I have never ever had an NPE from an Optional being null. Sure, complete null safety would be better of course, but in this very instance it ain't buying you much.
- mrkeen 4mo agoThis is what your choices are with regard to communicating to the compiler and other developers. Use a regular class to signal that you may or may not have a value. Wrap it in an optional to signal that you may or may not have a value. See the problem?