One of main Rust’s strengths is friendliness of compiler errors. Rust compiler very often suggest possible corrections and the first one frequently works. If I forget some import (use
in Rust parlance) needed for a typeclass to work, Rust compiler often suggest it to me. What will Scala compiler say?
object Main {
implicit class RichInt(value: Int)(implicit name: String) {
def print(): Unit =
println(s"$name: $value")
}
def main(args: Array[String]): Unit = {
// implicit val name: String = "bbb"
5.print()
}
}
value print is not a member of Int
Scala compiler doesn’t suggest any possible solution. Rust would search for some, order them by suitability and show e.g. 5 first ones.
Changing implicit
to given
won’t change the fact that Scala compiler doesn’t try to offer possible corrections.
IntelliJ offers implicits expansion display to help decrypting already working code that uses implicits: IntelliJ Scala plugin 2018.2: advanced “Implicit” support, improved patterns autocompletion, semantic highlighting, scalafmt and more | The IntelliJ Scala Plugin Blog That helps a lot, but works only when code is already correct. When trying to fix problems with incorrect code, compiler suggestions are required for good developer experience.