In his book “Domain Driven Design”, Eric Evans describes proper approaches for object-oriented programs to describe domains in expressive programs that take advantage of encapsulation to simplify architectures. It is a great book, and is a popular read for programmers interested in object-oriented design.
Mr. Evans makes a very interesting point at the bottom of page 250, quoting directly from the book …
“Operations that return result without producing side effects are called functions. A function can be called multiple times and return the same value each time. A function can call on other functions without worrying about the depth of nesting. Functions are much easier to test than operations that have side effects. For these reasons, functions lower risk.”
He goes on in the next page to push his functional advocacy even further …
“Therefore:
Place as much of the logic of the program as possible into functions, operations that return results with no observable side effects.” [Bold in the original text]
I am encouraged to see a book on object-oriented programming recognize the risk mitigating properties of functions, as well as the deleterious consequences of prolific side-effects. I believe this an important point because we are moving into a time when functional and object oriented programs must learn to coexist. This will confuse many object oriented programmers, and probably functional programmers as well. However, languages (primarily I am thinking of F# here) are being introduced that have responded directly to this challenge – and the results are promising.