News for hackers. Stuff that matters.
Re:Java's records, Lombok's data, and Kotlin's data classes by kerblang on Friday May 07, 2021 @03:18PM (#27079830)
> Never understood why people deem it has too many features

I'll start with one (key)word: `implicit`

I agree with your distaste for metaprogramming though.

Re:Java's records, Lombok's data, and Kotlin's data classes by lmm on Friday May 07, 2021 @09:35PM (#27082799)
Implicits are one feature that replace many features in other languages (Kotlin has probably 5 or 6 special features that each do limited subsets of what implicits can do, and still misses important parts of their functionality). There is some legitimate criticism to be made of Scala implicits (though I have yet to see a better alternative), but "too many features" isn't it.
Re:Java's records, Lombok's data, and Kotlin's data classes by lolinder on Friday May 07, 2021 @09:56PM (#27082935)
What Kotlin features do implicits serve to replace? I'm new to Scala and am having trouble imagining when I'd want to use an implicit, so I'm genuinely curious.
Re:Java's records, Lombok's data, and Kotlin's data classes by lmm on Friday May 07, 2021 @10:05PM (#27082987)
Off the top of my head: Extension methods. "with" contexts. Scope functions (by letting you write your own). Many of the things done with kapt (e.g. typeclasses, not that there's a good way to do them in Kotlin). Spring-style autowiring (not part of Kotlin proper, but seemingly the idiomatic way to use it). The magic last parameter lambda syntax thing (by letting you implement the magnet pattern).
Re:Java's records, Lombok's data, and Kotlin's data classes by beerbajay on Saturday May 08, 2021 @10:57AM (#27087699)
Scala implicits are used in a few different places, predominantly in library code where they can for example be used to derive instances of type classes. e.g. in circe:

  import io.circe.syntax._
  List(1, 2, 3).asJson
Where `asJson` requires an instance of an `Encoder`[1] and this Encoder can be derived with the help of implicits.

For you as a normal user, the two common places where you might use implicits are (1) for implicit classes providing syntactic sugar:

  // original
  def doSomething(a: A): B = ???
  val a: A = ???
  val b = doSomething(a)

  // with implicits
  implicit class AImplicits(a: A) {
    def doSomething: B = ???
  }
  val a: A = ???
  val b = a.doSomething
and for (2) implicit conversions. These are a foot-gun, so should be used in limited circumstances. At work, we use case classes in data pipelines then convert these to avro classes on save; there's lots of ways to do this, but as an example if you have an `Optional[Int]` and your avro constructor requires a nullable java `Integer` then `JavaConverters` won't save you and you'll need something like:

  implicit def optIntToInteger(optI: Option[Int]): java.lang.Integer = optI.map(Int.box).orNull
[1] https://circe.github.io/circe/api/io/circe/syntax/package$$E...
Re:Java's records, Lombok's data, and Kotlin's data classes by halfmatthalfcat on Friday May 07, 2021 @03:33PM (#27080001)
You can use Scala without introducing implicits and even if you have to interopt with a library that does require them, it's quite easy to learn how to use them. It's also easy to abuse them but then that's not really Scala's problem.

They are changing implicits in Scala 3 though with the "given" keyword which is more ergonomic.

Re:Java's records, Lombok's data, and Kotlin's data classes by cutler on Friday May 07, 2021 @04:30PM (#27080520)
Scala can't let go of implicits as they're a fundamental part of the language. I just don't believe this Scala 3 fudge to give the impression implicits are not alive and well beneath the surface.
Re:Java's records, Lombok's data, and Kotlin's data classes by esarbe on Saturday May 08, 2021 @05:11AM (#27085298)
Scala 3 takes the most common use cases for implicits and makes them more ergonomic. Implicits are still in the language, but not exposed as concept.

Odersky called the approach for Scala 3 "intent over mechanism."

Re:Java's records, Lombok's data, and Kotlin's data classes by asimpletune on Friday May 07, 2021 @04:08PM (#27080322)
You don’t have to use implicits though, but you’d be super happy they’re there should you ever be in a situation where they’re helpful
Re:Java's records, Lombok's data, and Kotlin's data classes by diroussel on Friday May 07, 2021 @04:41PM (#27080638)
Doesn’t a monad or for comprehension use implicits to find the right CanBuildFrom?

Are you suggesting to use scala without using for comprehensions? Or do you mean you don’t need to write your own?

It’s been a long time since I wrote scala, so may be getting it wrong.

Re:Java's records, Lombok's data, and Kotlin's data classes by valenterry on Friday May 07, 2021 @09:04PM (#27082647)
No it does not. A for-comprehension just requires that map/flatMap methods are available. No implicits or CanBuildFrom needed.
Re:Java's records, Lombok's data, and Kotlin's data classes by joshlemer on Friday May 07, 2021 @08:54PM (#27082584)
CanBuildFrom is gone in the 2.13 collections rewrite
Re:Java's records, Lombok's data, and Kotlin's data classes by ernst_klim on Friday May 07, 2021 @04:18PM (#27080403)
> I'll start with one (key)word: `implicit`

I don't think implicit counts as "too many features" or as something complex. Basically all it does is finding a canonical value in scope for a hole of certain type.

Re:Java's records, Lombok's data, and Kotlin's data classes by kjeetgill on Friday May 07, 2021 @05:17PM (#27080941)
I only worked in Scala briefly so maybe it's coming from Java habits, but implicits were huge pain. When first reading through code you don't really know if that function call you eyed over really has the params you think it does. It makes it WAY harder to track what's derived from what.

Either way, the local Scala guru there said the Scala community was starting to get over implicits.

Re:Java's records, Lombok's data, and Kotlin's data classes by valenterry on Friday May 07, 2021 @09:05PM (#27082654)
I think that's were it comes from: people that briefly worked with Scala in the past.

At some point it was true, but nowadays the problem is solved because IDEs will show you were an implicit is used and where it comes from. Without that, it was indeed more difficult - but also not more difficult than Java's reflection or DI (where you had and have even less help).

Re:Java's records, Lombok's data, and Kotlin's data classes by ernst_klim on Saturday May 08, 2021 @02:20PM (#27089516)
> When first reading through code you don't really know if that function call you eyed over really has the params you think it does.

Yeah, but don't you feel the same pain when using Spring's autowiring? Or python's (or C++ template) default arguments? Or dynamic method dispatching in any OO language, where you don't know what method you actually call? Or late bindings?

I don't see how implicits' implicitness is significantly worse than any other kind of implicitness common in other language.

Re:Java's records, Lombok's data, and Kotlin's data classes by kjeetgill on Sunday May 09, 2021 @04:12AM (#27094201)
I mean me personally? I'm very boilerplate tolerant. I'm not a fan of Dependency Injection/Auto Wiring for similar reasons and I've never found wiring boilerplate to be too painful. In fact I'd love even more explicitness and manual wiring for almost everything like disk, network, or even clock access aka passing capabilities!

Default params are generally fine since they're hidden on the implementation side but explicit if they vary at the caller site.

And even dynamic dispatch I try to use carefully and sparingly. I just like really explicit programs.

Re:Java's records, Lombok's data, and Kotlin's data classes by ernst_klim on Sunday May 09, 2021 @07:05AM (#27095020)
> I'm not a fan of Dependency Injection/Auto Wiring for similar reasons

I see. My point was that such things are pretty common in most contemporary languages and I don't see how Scala is special in this regard.

Yes, unlike Go or Java, implicits are part of the language spec and not some metaprogramming magic on top of it, but I'm not sure it's a bad thing.