I’ve been trying to catch up on all of these related threads recently while also asking myself where i have observed problems and downsides to implicits (personally when first learning scala, and more recently when reading other people’s code as they learn it).
Several of the cases have been brought up already here and elsewhere: conversions, poor compiler / tooling output, explaining them to noobs, etc. I think the poor compiler/tooling issue is HUGE. Intellij’s recent steps forward have migrated the situation from ‘untenable’ to ‘fine for non-complex use cases’. But there’s still a ways to go there.
The biggest meta-issue i’ve seen for early-to-mid scala folks, myself included, ended up being “When should i use them” and “How can i avoid horrible-to-use and horrible-to-understand code when using them”. My understanding on this has evolved quite a bit through a combination of:
- Personal experience / banging head against the wall / hard knocks
- Learning MUCH more about FP through years of study, conferences, and videos
- Internalizing the mathematical foundations of FP
- Learning Haskell
Now, after many years, i feel I can use implicit
s effectively and responsibly, not to the detriment of the codebase i’m working in. The biggest takeaway i’ve internalized about implicit
s is indeed as Martin mentions here:
- They should generally be treated as constraints rather than parameters.
YES!!!
This realization took me a long time to come to, but looking back over my last 6+ years with scala, most of the non-tooling problems i’ve seen with implicits seem to roughly boil down to treating them as “just another parameter” that one can helpfully use the syntax around to avoid typing a few characters. The complexity and readability costs of this mistake are common, cumulative, and in my opinion the biggest downside to existing implicits.
Marking this powerful, useful concept as something distinct from “just another parameter” (even if, in low level reality, that’s what it boiled down to) is likely to have a huge impact on reducing the future detrimental effects i mentioned above, as well as help push the new-scala-dev training / explanation of implicits and their responsible use into a much better (and simpler) direction.
This is why my own thoughts on the current proposal have changed. I no longer consider @lihaoyi 's “alternate proposal X is much more familiar to people” which retains more of the familiar syntax to be a better approach, whereas i would have initially. I think that the lack of familiar syntax should be considered a feature rather than a bug for a concept as powerful and easy to misuse as implicit
s. This feature should be “easy to use ‘the right way’” and “hard to use ‘the wrong way’” for some suitable definition thereof, and if familiar syntax doesn’t achieve that goal because it maps too easily into the familiar (and thus to misuse), then the familiarity is a disadvantageous flaw in any proposal.
My two cents…