Proposal: make assisted arguments explicit
See original GitHub issuekotlin-inject’s way of injecting dependencies with assisted arguments is really clever but I’ve been thinking it’s very implicit and hidden for readers. Thoughts on making it explicit in some manner? Using dagger-like @Assisted
annotation is one option, but I’m not sure if you’d want that. It’ll also remove the restriction of keeping assisted arguments at the end of a constructor, which is another hidden restriction.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13 (13 by maintainers)
Top Results From Across the Web
Proposal: A built-in Go error check function,
The ideas discussed in the draft design centered around a new unary operator check which simplified explicit checking of an error value returned ......
Read more >The Explicit Syntax of Implicit Arguments - jstor
The proposal I make is very simple. Both types of implicit arguments consist of a (possibly partial) set of 4>-features, a c|>-set. SIAs...
Read more >Proposal: Auto-propagated function parameters #2327 - GitHub
The purpose of this proposal is to provide an ergonomic yet explicit way to get access to a set of variables deep in...
Read more >Why explicit self has to stay - Neopythonic
Bruce Eckel has blogged about a proposal to remove 'self' from the formal parameter list of methods. I'm going to explain why this...
Read more >A proposal for extending the meaning of the 'explicit' keyword
This approach is supposed to have advantages over using templates to constrain the arguments, such as not requiring template instantiations, and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok here’s my proposal:
Introduce an
@Assisted
annotation to make assisted arguments explicitproblem
It can be not obvious which arguments are assisted or which are expected to be provided by the graph. This can make it confusing on why you are unable to inject a certain type. While there is extra flexibility with this on choosing which args you want to inject or not at the usage site, this feature isn’t often used.
solution
All assisted arguments must be annotated with an
@Assisted
annotation. This will limit the usage site to providing exactly those parameters in the same order they are declared. For example with the declaration:the only allowed way to inject that class is
these will fail to compile with an error about missing or mismatched args
migration
When this feature is implemented the behavior will be selected based on if there’s any args annotated with
@Assisted
. If so the new strategy will be used, otherwise a warning will be printed to suggest annotating the arg. This warning will then become an error in a future release.You mean something like this? 😉 (in reality I’d probably go for something a bit different since the lists aren’t expected to be super long but yea)