From the book "functional programming in Scala", there is an section about how to write the random number generator in functional way.
It gives an example about scala.util.Random:
Even if we didn’t know anything about what happens inside scala.util.Random, we can assume that the object rng has some internal state that gets updated after each invocation, since we’d otherwise get the same value each time we called nextInt or nextDouble. Because the state updates are performed as a side effect, these methods aren’t referentially transparent. And as we know, this implies that they aren’t as testable, composable, modular, and easily parallelized as they could be.
The last sentence, it says that is not:
- testable
- composable
- modular
- easily parallelized
In the later content, it explained the testable part, because how to understand the other 3 aspects?
Aucun commentaire:
Enregistrer un commentaire