Last active
August 29, 2015 14:21
-
-
Save caente/b6736258055551761fe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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