Skip to content

Instantly share code, notes, and snippets.

@caente
Last active August 29, 2015 14:21
Show Gist options
  • Save caente/b6736258055551761fe5 to your computer and use it in GitHub Desktop.
Save caente/b6736258055551761fe5 to your computer and use it in GitHub Desktop.
object types {
def divide(i: Int): Int = (i/5).toInt
def subtract(i: Int): Int = i - 10
def multiply(i: Int): Int = i * -1
def allOK(i: Int):Int = {
val s1 =divide(i)
val s2 = subtract(s1)
val s3 = multiply(s2)
s3
}
def allBAD(i: Int):Int = {
val s1 =divide(i)
val s2 = multiply(s1)
val s3 = subtract(s2)
s3
}
}
/*
scala> types.allOK(1)
res19: Int = 10
scala> types.allBAD(1)
res20: Int = -10 // A bug!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment