New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get rid of Optional (#52) #93
Conversation
@@ -35,7 +35,7 @@ public void testLoadNull(VertxTestContext testContext) throws Throwable { | |||
session.find( GuineaPig.class, 1 ) | |||
.whenComplete( (result, err) -> { | |||
try { | |||
assertThat( result ).isNotNull(); | |||
assertThat( result ).isNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you squash this in the previous commit, please?
Isn't the idea of Optional to allow a more functional approach to code (it has functions like |
It's more likely to be the cause of bugs than it is to protect us from bugs.
e984305
to
752e2fa
Compare
.thenCompose( v -> queryExecutor().selectLong(selectIdSql, new Object[0], factory) ) | ||
.thenApply(Optional::get); | ||
.thenApply( id -> id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this last thenApply
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, it does a widening cast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This wouldn't be necessary if Java had declaration-site variance grumble.)
That's not what "functional" means. (Not for any meaningful definition of "functional" anyhow.) Look, we have a reasonable-sized codebase that uses So this is just cargo-cult stuff. The only people who think that calling the monomorphic function |
P.S. @DavideD If you like, I can write you a function |
(That comment wasn't aimed at you, of course, @DavideD, more at the people who designed this thing.) |
Sure, but even so... was it really helpful as far as comments go? Anyway, my point is that |
As far as I can tell most programmers don't like it, so I'm not against removing them from the API. I'm not sure this is the right place to discuss it though, as people won't see it. |
Right, that's why I opened #52 a couple of months ago ... to try and get some feedback. (And we have to make a decision on this ASAP.) |
Optional is evil |
There is a serious drawback for the
see https://softwareengineering.stackexchange.com/questions/364211/why-use-optional-in-java-8-instead-of-traditional-null-pointer-checks for some other reasons No idea about the |
+1 on removing optional |
This is indeed something that arises occasionally (really the only case I know of is caching/memoizing), it's not a distinction we need to make in the API of hibernate-rx. |
NIce, thanks |
As proposed in #52, this change kicks
Optional
out of our code base.Justification:
get()
on an uninitialized one (unlike other langs, Java doesn't have sum or union types) ... even worse, nothing stops you from assigningnull
to the typeOptional
Optional
is assignable toObject
get()
to (unlike Ceylon, Java doesn't have intersection types)Does anybody want to step up and defend this 'orrible thing?