Skip to content

Instantly share code, notes, and snippets.

@mpilquist
Last active January 3, 2016 06:19
Show Gist options
  • Save mpilquist/8421429 to your computer and use it in GitHub Desktop.
Save mpilquist/8421429 to your computer and use it in GitHub Desktop.
Distribution of `Option`, `Either`, `Try`, `scalaz.\/`, `scalaz.Validation`

Distribution of Option, Either, Try, scalaz.\/, scalaz.Validation on a large project that started in 2009 and has about ~425,000 SLOC of Scala:

› find . -name '*.scala' -exec grep -o "Option" {} \; | wc -l
    7747
› find . -name '*.scala' -exec grep -o "Either" {} \; | wc -l
     547
› find . -name '*.scala' -exec grep -o "Try" {} \; | wc -l
     129         
› find . -name '*.scala' -exec grep -o "\\\/" {} \; | wc -l
    2159
› find . -name '*.scala' -exec grep -o "Validation" {} \; | wc -l
     715

Caveats:

  • Project was started in 2009
  • Scalaz was introduced in early 2012
  • \/ was introduced August 2012
  • Project was upgraded to Scala 2.10 in winter of 2012-2013

Observations:

  • Option is used extensively in data modeling and as failure abstraction when the reason for failure is not needed.
  • \/ is the primary failure abstraction, which explains its rapid usage after introduction.
  • Validation is typically only used when accumulating errors but some code still uses it monadically. This code will be refactored over time, which will result in an overall decrease in Validation usage.
  • Try is used occassionally when working with Futures but codebase prefers Future[ErrorType \/ A].
  • Either is typically only used when the value represents two choices with no preference -- that is, the left side is equally correct/valid as the right side. Some older subsystems still use Either as a failure abstraction and as they are refactored to use scalaz.\/, the Either usage will decrease.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment