Slide 16
Slide 16 text
Command-query separation: Example 2/2
val a = IntList(1, 2)
val b = IntList(3, 4)
val c = a append b
Expected: a={1, 2}, b={3, 4}, c={1, 2, 3, 4}
Surprising result: a={1, 2, 3, 4}, b={3, 4}, c={1, 2, 3, 4}
Function append should not modify a or b
because it returns a result
Function > Responsibility > Command and query