At first I really thought they were dangerous (because of hidden dependencies), but as I’ve worked with them more and more, they don’t seem to be. And I agree with the tweet, they feel better to me than the Spring way of DI.
Anyway, I was just curious if they had ever been discussed before, and what the feelings were about them.
Edit: I should mention I’m only talking about parameters here, not implicit conversions.
this would be better than the current context receiver approach
// this code can't be expressed using context receivers as they only consider types instead of names+types
fun maxLength(implicit a:String,implicit b:String)=max(a.length,b.length)
val a:String=""
val b:String=""
maxLength()
then context receivers can be thought as a specialized form and deprecated
// context(String)fun getLength1()=length
// fun String.getLength2()=length
fun getLength3(implicit this:String)=length
this makes code more clear and less verbose, less error prone
context(A,B,C)xxx()=length // whose length?
with(a){
with(b){
with(c){
xxx()
}
}
}
// can be written as
fun yyy(implicit a:A,implicit b:B,implicit c:C)=a.length // self explanatory
val a=...
val b=...
val c=...
yyy()