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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Left and Right in Eithers #25950

Merged
merged 1 commit into from
Mar 15, 2023
Merged

Switch Left and Right in Eithers #25950

merged 1 commit into from
Mar 15, 2023

Conversation

bryophyta
Copy link
Contributor

@bryophyta bryophyta commented Mar 3, 2023

What does this change?

Switches the Left and Right types associated with the ModelOrResult object, and refactors the controllers which use this object (either directly or indirectly).

Why?

The convention in Scala is to use Right as the 'success' condition, as noted in this comment on the ModelOrResult object:

https://github.com/guardian/frontend/blame/f5604316a946a4113807de3fe2af74ed79307877/common/app/common/ModelOrResult.scala#L10-L12

As of Scala 2.13 it looks like treating Right as the error case is deprecated and elsewhere in Frontend we use Right as the success case:

https://github.com/guardian/frontend/blob/0657f594e2fd51125d28df9048c48d6eede26bb6/admin/app/model/deploys/RiffRaff.scala#L49-50

So in accordance with our recommendation to follow the principle of least surprise in our code, it makes sense to standardise on the broader convention, where possible. (As much as it pains me, as a left-handed developer 馃槩馃槄.)

Testing

I've done a test deployment in CODE and clicked around a bit, including in apps like Preview which sometimes have surprising dependencies on e.g. Article code. There were no obvious issues, and I'm hoping that this is a case where the type system and tests will give us some security. But having said that, it feels like quite a big (and not-strictly-necessary) change, so I'd appreciate any thoughts about whether we can be confident that won't break anything!

@bryophyta bryophyta marked this pull request as ready for review March 3, 2023 16:54
@bryophyta bryophyta requested a review from a team as a code owner March 3, 2023 16:54
@bryophyta bryophyta changed the title Spike: Switch Left and Right in Eithers Switch Left and Right in Eithers Mar 7, 2023
@mxdvl
Copy link
Member

mxdvl commented Mar 13, 2023

I think your link to the Principle of least astonishment is not quite right: https://github.com/guardian/recommendations/blob/main/coding-with-empathy.md#recommendations

This made me chuckle: scala/scala#6682 (comment)

@bryophyta
Copy link
Contributor Author

I think your link to the Principle of least astonishment is not quite right

Good call, thanks! (Interestingly, it looks like I forgot to put a URL in at all, and so [link text]() will take a default href of /?)

Copy link
Contributor

@georgeblahblah georgeblahblah left a comment

Choose a reason for hiding this comment

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

馃憤 this is a great refactor @bryophyta, and I think it will definitely help make this code more readable

Copy link
Contributor

@Georges-GNM Georges-GNM left a comment

Choose a reason for hiding this comment

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

Seems good to me!

Copy link
Member

@AshCorr AshCorr left a comment

Choose a reason for hiding this comment

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

馃憤

@bryophyta
Copy link
Contributor Author

Thanks everyone for the reviews!

@prout-bot
Copy link
Collaborator

Overdue on FRONTS-PROD, ADMIN-PROD (merged by @bryophyta 30 minutes and 9 seconds ago) What's gone wrong?

@prout-bot
Copy link
Collaborator

Seen on FRONTS-PROD (merged by @bryophyta 40 minutes and 32 seconds ago)

@prout-bot
Copy link
Collaborator

Seen on ADMIN-PROD (merged by @bryophyta 40 minutes and 58 seconds ago)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants