1
votes

Taken from "Scala with cats" (page 18):

Implicit Conversions
When you create a type class instance constructor using an implicit def, be sure to mark the parameters to the method as implicit pa­rameters. Without this keyword, the compiler won’t be able to fill in the parameters during implicit resolution. implicit methods with non‐implicit parameters form a different Scala pattern called an implicit conversion. This is also different from the previous section on Interface Syntax, because in that case the JsonWriter is an implicit class with extension methods. Implicit con­version is an older programming pattern that is frowned upon in mod­ern Scala code. Fortunately, the compiler will warn you when you do this. You have to manually enable implicit conversions by importing scala.language.implicitConversions in your file

Can anyone please sum up well why implicit conversion are deprecated? What were there limit or issues? Why the approach with implicit parameters is better?

Note I know how to use the modern approach well, including chaining implicit and all. I am just curious as to what was the issue and why it was deprecated.

1
Implicit derivation is very different from implicit conversions the former is a logic proof when you can say something like I can derive the Monoid[List[Map[String, Option[Int]]]] because I can derive the Monoid of List because I can derive the one of Map because I can derive the one of Option because I know there is one for Int - The latter, is just a way of saying I will turn an A into a B every time a B is needed but the code produce an A, in general, such pattern leads to code that is hard to read (understand), hard to maintain and can hide costly oeprations.Luis Miguel Mejía Suárez
However, there are indeed "valid use cases". But, IMHO, those a little and should be reserved when there is no other cleaner solution. For an in-depth discussion about the topic read: contributors.scala-lang.org/t/…Luis Miguel Mejía Suárez

1 Answers

2
votes

Martin Odersky, the inventor of Scala, has indicated that implicits (and implicit conversions) are being deprecated in scala 3.1 and will eventually be removed from the language altogether.

the implicit functionality will be replaced with Extension Methods and Givens. Extension Methods and Givens provide a more tighter functional solution that doesn't introduce the unsuspecting and hidden side effects that implicits cause. Odersky now views implicits as a “recipe for disaster" and are "too implicit" which was his motivation to replace their functionality in 3.x.

https://www.slideshare.net/Lightbend/scala-3-is-coming-martin-odersky-shares-what-to-know

https://hub.packtpub.com/is-scala-3-0-a-new-language-all-together-martin-odersky-its-designer-says-yes-and-no/