Should extension methods/parent methods be used vs normal methods?
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 15
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
It appears that most of the code relies on an enum with extension methods or methods in the parent, vs defining the methods in the child classes.
Won't this potentially limit JVM optimizations? Consider the following example (https://godbolt.org/z/48rqPqE75)
def example(x: Result[Int, Int]): Iterator[Int] =
x match
case xx: Result.Ok[Int] => xx.iterator
case _: Result.Err[Int] =>
println("ERROR")
Iterator.empty
Note that the call to xx.iterator will call Ok.Iterator directly.
In the current implementation, this will do another instanceof check, which would be avoided if the methods were defined in the child classes.
I understand that this is a micro optimization, but if the plan is to move this to the stdlib, we might as well make sure that it's performant.
Contributor guide
No contributing guide indexed for this repository
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 with src/main/scala/steps/result/package.scala and compare the enum extension and parent methods with methods on the child classes. Reproduce or inspect the JVM behavior in the linked Godbolt example, then determine whether the implementation should change for performance. Done means reaching and documenting a clear design decision; no project test is named in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100