Re:My takeaways from "Clean Code"
by jasonlotito on Tuesday May 28, 2013 @08:51PM
(#5783909)
Having no side effects doesn't mean it can't do something. Only that it shouldn't do anything unexpected.
That should only make the store item available. It shouldn't re-enable a sale that was on the storeItem when it was made unavailable.
[ Parent
| on HN ]
That's a zero-argument method but not a zero-argument function. That is, if you view makeAvailable as a function, storeItem is an implicit argument to it. In fact, storeItem is probably an object with several fields, so there are arguably several implicit arguments. To my eye, the name "makeAvailable" suggests a side-effect too.
In any case, it's fine for two rules such as "avoid side effects" and "prefer zero- or single-argument functions" to be in tension with one another. I don't buy that zero-or-one idea, though. A function should have as many arguments as it makes sense for it to have.
Isn't that a side effect?
Yeah, pretty much. I generally agree with this definition:
http://en.wikipedia.org/wiki/Side_effect_(computer_science)
I think instead of "side effect" the author should have used the more traditional term of cohesion:
Re:My takeaways from "Clean Code"
by ruficornis on Tuesday May 28, 2013 @10:39PM
(#5784260)
That is more of an effect, not a side effect, no?
Something still happens, but nothing very unexcpected. If a doctor gives you medicine for an ailment, you don't want it to have many side effects, but it intended effect is still desired (theoretically). Prehaps it should effect only what it needs to in order to give you or the next step it's output, not changing some finite machine state (unless...)
That's not how I've usually seen the term side effect used in CS: http://en.wikipedia.org/wiki/Side_effect_(computer_science)
In jasonlotito's example, he's definitely modifying state.
(Mind you, I don't think side effects should be banned outright or anything like that. But minimizing them is frequently a nice idea.)
Re:My takeaways from "Clean Code"
by ruficornis on Tuesday May 28, 2013 @11:44PM
(#5784468)
Sorry, I was wrong. I did not read the comment closely nor was I familiar with the CS definition. Thank you for the information.