playframework / playframework/playframework
Constants should be final
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 12.6k
- Forks
- 4k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 29
Description
Many of our constants in Play are defined in traits. Most of the time they are declared as vals. I suggest we switch to final val. This makes sense since the value is constant and (as I understand it) the only reason to use a trait is to allow users to mix in the trait to their classes to get access to those constants, not to be able to override them.
A significant benefit here is that its easy to add new constants to traits when they are final vals, since they can be compiled to default methods in Scala 2.12+. That allows us to have stronger binary compatibility guarantees moving forward.
Another option of course is to disable the ability to access constants through traits, and require those constants to be imported from objects. I don't have a strong opinion either way, but changing the constants to final val is a better option for backwards compatibility.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inventorying the Play traits that define constants and identify which are declared as val rather than final val. Review the Scala 2.12+ default-method behavior and binary-compatibility implications described in the issue. Done means the applicable constants use final val without breaking existing trait access; the issue names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100