Wednesday 6 June 2012

Clean code: exceptions for Scala?

At the junction of OOP and FP Scala contributors are doing great things. While reading librarie's code I finding a lot of places where author's ignoring gode coding style for the name of performance or interface presentation. Can understand this, they are doing library.
Today found some interesting example called "my mother would kill me for this":




/**
 * The left side of the disjoint union, as opposed to the `Right` side.
 *
 * @author <a href="mailto:research@workingmouse.com">Tony Morris</a>, Workingmouse
 * @version 1.0, 11/10/2008
 */
final case class Left[+A, +B](a: A) extends Either[A, B] {
  def isLeft = true
  def isRight = false
}

and

/**
 * The right side of the disjoint union, as opposed to the `Left` side.
 *
 * @author <a href="mailto:research@workingmouse.com">Tony Morris</a>, Workingmouse
 * @version 1.0, 11/10/2008
 */
final case class Right[+A, +B](b: B) extends Either[A, B] {
  def isLeft = false
  def isRight = true
}

not bad)


No comments:

Post a Comment