News for hackers. Stuff that matters.
Re:Java 20 Is Out! by dcminter on Tuesday March 21, 2023 @01:08PM (#35249171)
It's really nice syntactic sugar. Complicated conditional logic cluttered with redundant types turns into a series of simple patterns. "Just" makes it easier to not make stupid bugs (I'm all for it).
Re:Java 20 Is Out! by therealdrag0 on Tuesday March 21, 2023 @04:07PM (#35251788)
Agreed. Example from Scala

  // Given an Option
  val maybeThing: Option[String] = getThing()  

  // Classic
  if (maybeThing.isDefined) {
    useThing(maybeThing.get)
  } else {
    NotFoundResponseEtc()
  }  

  // Pattern matching (not too IDE auto generated exhaustive match cases!)
  maybeThing match {
    case Some(thing) => useThing(thing)
    case None        => NotFoundResponseEtc()
  }

This scales well when matching a higher cardinality of things like a variety of Exceptions or enums or other tuple responses like Either etc.