Books

Monday, June 27, 2016

Understanding Implicits in Scala

I knew about the maxim: "Implicits are evil" way before I started learning and using Scala. So by the time I started running into them in codebases, I was already biased. It was thus easier to raise my hands in despair at the "magic" that is implicit and just condemn their existence.

Obviously such a view is not healthy. So I decided to do what any sane human would do: If I am going to continually bitch about something, I should at least know some one or two things about what I am bitching about.

This post captures my understanding of how implicits work in Scala thus far. Not in the sense of how they work at the compiler or implementation level, but how they work in the sense of what they do and how to reason about them when encountered in a codebase.

It is not about when to make the decision to use or not use implicits. Or how to use them "tastefully". My current level of mastery of the Scala language does not permit me to make such pontification. Hopefully in the nearest feature, a post like this would follow.

Should in case you were like me a couple of months back, and just want a clue about what the hell is the magic going on with implicit, then you will find this post useful.

So let us get right to it.