|
|
|
|
|
by _gabe_
1029 days ago
|
|
I should have been more specific, the way Bob Martin phrases it in the book is functions should have 0 side effects. Then he shows an example at the end of the chapter where the entire example works by creating a giant class full of member functions that mutate the owning class. I (and I think most people) assume that a function with 0 side effects means that if you call the function, the state of the object should be the same before and after the function call (and the rest of the external system should remain unchanged). But, according to the examples in the book, it seems like Bob Martin only considers it a side effect if some external state is modified as a result of the function call. The best example of a function without side effects would be sin(x). You call the function with an input and it returns a completely new output. The function should be thread safe and easy to isolate because it never touches any outside state. |
|