You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
The current export clause feature allows to achieve it only partially / not smoothly.
Currently, there are two options with export:
write a wildcard, excluding all unrelated members export fieldDelegateTo.{unrelatedMember => _, _}
list all methods from the trait export fieldDelegateTo.{foo1, foo2, ... fooN}
The first option is not only a boilerplate, it has a high risk of exporting too many unrelated public members.
You have to explicitly list all members to "mute". You can easily skip some.
If a new member is added to the class, most likely you will forget to update all the exports.
It may lead to context pollution.
It will potentially increase compilation time, show a lot of unexpected members in the completion list in IDE, etc...
The second option is also a boilerplate code.
You have to list all the members.
You can accidentally export some unrelated member.
You have to update all exports in case a new method is added to the trait.
Without "proper" delegation, export feels a little bit incomplete.
The motivation for export was to make "composition over inheritance" require less boilerplate code.
It's very likely that wildcard import will be overused (cause programmers are lazy), leading to all the cons listed above.
We need some new syntax, which would allow us to only export methods of a specific trait.
Something like export delegate.{_: MyTrait1}:
From the first glance, this feature doesn't require a lot of effort (patch import selector parsing and restrict filtering of exported methods in Namer.scala).
The most difficult is as always to agree on the syntax.
The text was updated successfully, but these errors were encountered:
See https://www.wikiwand.com/en/Delegation_pattern
The current
export
clause feature allows to achieve it only partially / not smoothly.Currently, there are two options with
export
:export fieldDelegateTo.{unrelatedMember => _, _}
export fieldDelegateTo.{foo1, foo2, ... fooN}
The first option is not only a boilerplate, it has a high risk of exporting too many unrelated public members.
You have to explicitly list all members to "mute". You can easily skip some.
If a new member is added to the class, most likely you will forget to update all the exports.
It may lead to context pollution.
It will potentially increase compilation time, show a lot of unexpected members in the completion list in IDE, etc...
The second option is also a boilerplate code.
You have to list all the members.
You can accidentally export some unrelated member.
You have to update all exports in case a new method is added to the trait.
Without "proper" delegation,
export
feels a little bit incomplete.The motivation for
export
was to make "composition over inheritance" require less boilerplate code.It's very likely that wildcard import will be overused (cause programmers are lazy), leading to all the cons listed above.
We need some new syntax, which would allow us to only export methods of a specific trait.
Something like
export delegate.{_: MyTrait1}
:From the first glance, this feature doesn't require a lot of effort (patch import selector parsing and restrict filtering of exported methods in
Namer.scala
).The most difficult is as always to agree on the syntax.
The text was updated successfully, but these errors were encountered: