I've seen uses of implicits fall into three categories:<p>(1) Dependency injection, e.g. ExecutionContext<p>(2) DSLs/syntax sugar, e.g. custom string interpolation, specs2<p>(3) Typeclasses and type-level programming, e.g. Play JSON Reads/Writes, cats, shapeless<p>The more I have seen Scala, the more I realize that #1 is cancer.<p>Implicits should <i>not</i> be used to reduce the number of characters typed. If used at all, they should be used for a better reason, e.g. it is a necessary part of a typesafe pattern, like typeclasses.
I heartily recommend [splain][0] to anyone debugging non-trivial implicits. It is a scalac compiler plugin that, among other things, will swap out the horribly unhelpful "implicit not found" or "diverging implicit expansion" messages for an indented and annotated representation of the search tree that the compiler went through before giving up.<p>`-Xlog-implicits` is good to use every now and then, but it quickly becomes unreadable for any decent sized project.<p><pre><code> [0]: https://github.com/tek/splain</code></pre>
It will be interesting to try out implicits in the upcoming Twitter's Reasonable Scala Compiler [0]<p>According to [1] a working version will be ready before originally planned:<p>> Recently, Stu Hood came up with a groundbreaking idea. He suggested
> that Rsc can become useful much earlier that we initially thought.<p>[0] <a href="https://github.com/twitter/rsc" rel="nofollow">https://github.com/twitter/rsc</a><p>[1] <a href="https://github.com/twitter/rsc/commit/ebc3019c06c9e175311541637ec31047fb914c4b" rel="nofollow">https://github.com/twitter/rsc/commit/ebc3019c06c9e175311541...</a>
For when you've completed that here's an application (with an amusing name): <a href="http://eugenezhulenev.com/blog/2017/04/26/type-level-instant-insanity-in-scala/" rel="nofollow">http://eugenezhulenev.com/blog/2017/04/26/type-level-instant...</a>
Re implicits and their interplay with macros: Achieving 3.2x Faster Scala Compile Time<p>Diagnostics:<p>- A method takes an implicit parameter to be filled in by the compiler<p>- the Scala compiler synthesizes an argument for that parameter using macros<p>- instead of using an existing value in the implicit scope<p>Conclusion: that's why a small source file took so long to typecheck.<p>Details at <a href="https://jobs.zalando.com/tech/blog/achieving-3.2x-faster-scala-compile-time/" rel="nofollow">https://jobs.zalando.com/tech/blog/achieving-3.2x-faster-sca...</a>
Also see Martin Odersky's recent talk about abstracting context using implicits <a href="https://youtu.be/uiorT754IwA" rel="nofollow">https://youtu.be/uiorT754IwA</a>
If you keep an eye on Indeed.com and Angel.co you'll notice a decline in Scala adoption over the last few years. I can't help thinking implicits are partly responsible for this. They're certainly the main reason I ditched Scala. More than any other language there seem to be more exmaples, with Scala, of a team trying it then switching to something simpler.
I think implicits are fine as long as they're used primarily for the typeclass pattern. The extension methods and conversions aspect of implicits should be confined to library DSLs
i wonder if implicits could present a security risk, insofar as the compiler may grab some [perhaps mistakenly in-scope] identifier which has sensitive data on it.