Skip to content

8268469: Update java.time to use switch expressions #4433

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

Closed
wants to merge 8 commits into from

Conversation

pconcannon
Copy link
Contributor

@pconcannon pconcannon commented Jun 9, 2021

Hi,

Could someone please review my code for updating the code in the java.time packages to make use of the switch expressions?

Kind regards,
Patrick


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8268469: Update java.time to use switch expressions

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4433/head:pull/4433
$ git checkout pull/4433

Update a local copy of the PR:
$ git checkout pull/4433
$ git pull https://git.openjdk.java.net/jdk pull/4433/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4433

View PR using the GUI difftool:
$ git pr show -t 4433

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4433.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 9, 2021

👋 Welcome back pconcannon! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 9, 2021
@openjdk
Copy link

openjdk bot commented Jun 9, 2021

@pconcannon The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Jun 9, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 9, 2021

Webrevs

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Updates look good Patrick

@openjdk
Copy link

openjdk bot commented Jun 9, 2021

@pconcannon This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8268469: Update java.time to use switch expressions

Reviewed-by: lancea, naoto, dfuchs, iris, chegar

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 9, 2021
Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

Looks good overall. Some misplaced comments. Also, copyright years should be updated.

Copy link
Contributor

@jodastephen jodastephen left a comment

Choose a reason for hiding this comment

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

My biggest comment is the spaces used to align, which I strongly object to. I agree with @dfuch comments too.

}
return with(date.plus(amountToAdd, unit), time);
return switch (chronoUnit) {
case NANOS -> plusNanos(amountToAdd);
Copy link
Contributor

Choose a reason for hiding this comment

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

Still has unnecessary alignment

There are lots of cases in the PR where -> is still aligned. I'd like to see all of them unaligned.

return 335 + leap;
}
return switch (this) {
case JANUARY -> 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary alignment

Copy link
Member

Choose a reason for hiding this comment

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

The vertical alignment improves readability in these short-line cases. Removing the spaces before the arrows will make it a little harder to discern the difference between the cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is your codebase, not mine, so it is up to you. Aligning things by column is generally frowned on in most style guides because it handles refactoring poorly, resulting in lots of needless change (or people forgetting to realign things - I had to deal with a rogue aligned Javadoc signature today in a PR where exactly that had happened). I also don't see how you write a style guide rule for when these should be aligned and when they should not.

Anyway, this PR isn't really the right place for this discussion - I'm not blocking the PR on this basis (and I'm not an official Reviewer anyway).

Copy link
Member

@dfuch dfuch Jun 17, 2021

Choose a reason for hiding this comment

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

I have a slight preference for the aligned version in the cases where the lines are short and the number of spaces used for padding is not unreasonable. I find the code gains in readability in these cases. In the case where the lines are long - I agree with Stephen that the alignment doesn't bring much readability - and sometime it may even be detrimental as it makes long lines longer. Stephen, would that be an acceptable compromise?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its certainly a reasonable position to take (ie. if thats what OpenJDK wants to do, its fine by me).
I'm more interested to see how you would write such a thing down in the coding standards that doesn't make the standard worthless.

return 335 + leap;
}
return switch (this) {
case JANUARY -> 1;
Copy link
Member

@dfuch dfuch Jun 17, 2021

Choose a reason for hiding this comment

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

I have a slight preference for the aligned version in the cases where the lines are short and the number of spaces used for padding is not unreasonable. I find the code gains in readability in these cases. In the case where the lines are long - I agree with Stephen that the alignment doesn't bring much readability - and sometime it may even be detrimental as it makes long lines longer. Stephen, would that be an acceptable compromise?

@pconcannon
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 25, 2021

Going to push as commit 1d16797.

@openjdk openjdk bot closed this Jun 25, 2021
@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 25, 2021
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 25, 2021
@openjdk
Copy link

openjdk bot commented Jun 25, 2021

@pconcannon Pushed as commit 1d16797.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@pconcannon pconcannon deleted the JDK-8268469 branch July 6, 2021 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

7 participants