Skip to content
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

add optional monad from java8 #70

Closed
wants to merge 1 commit into from
Closed

add optional monad from java8 #70

wants to merge 1 commit into from

Conversation

acoburn
Copy link
Contributor

@acoburn acoburn commented May 19, 2015

See: https://jira.duraspace.org/browse/FCREPO-1550

This is a non-functional change, representing an effort to get my feet wet with Java8. I would appreciate it if @ajs6f could look over the code to make suggestions where the expressions are not idiomatic.

@@ -81,7 +82,7 @@ public FcrepoResponse head(final URI url)
final HttpRequestBase request = HttpMethods.HEAD.createRequest(url);
final HttpResponse response = executeRequest(request);
final int status = response.getStatusLine().getStatusCode();
final String contentType = getContentTypeHeader(response);
final Optional<String> maybeContentType = getContentTypeHeader(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and all that follows on it below with the use of Optional::ifPresent) isn't unarguably great. See Stuart Marks' explanation. Long story short: you're shortening code but trading an explicit nullcheck for an object creation and an implicit nullcheck. I don't have a problem with it, but I know some people wouldn't be enthused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajs6f this is precisely the feedback I'm looking for. It's a bit unclear to me when Optional should be used, if at all in this code. That is, I'm not at all attached to the refactoring in this PR -- it is more an exercise in getting to know the Optional class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, so this is the thing. Here're some thoughts:

Some of the gains in brevity in the main code are lost by expanded test code. You're eventually losing a few dozen lines over a few hundred lines, so the real question is: is it clearer? That's a matter of taste. See below for further comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to close this PR and view it as a practice exercise. I agree that it doesn't seem to add much in clarity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be looking harder at Stream. There's a lot of quick wins in that one.

@acoburn acoburn closed this May 20, 2015
@acoburn acoburn deleted the java8 branch July 29, 2015 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants