3 ms·
Having no side effects doesn't mean it can't do something. Only that it shouldn't do anything unexpected. storeItem.makeAvailable(); That should only mak
by jasonlotito 13y ago
Having no side effects doesn't mean it can't do something. Only that it shouldn't do anything unexpected.
storeItem.makeAvailable();
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.
- gruseom 13y agoThat'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.
- colomon 13y agoIsn't that a side effect?
- ruficornis 13y agoThat 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...)
- colomon 13y agoThat's not how I've usually seen the term side effect used in CS: http://en.wikipedia.org/wiki/Side_effect_(computer_science) 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.)
- ruficornis 13y agoSorry, I was wrong. I did not read the comment closely nor was I familiar with the CS definition. Thank you for the information.
- blazespin 13y agoYeah, pretty much. I generally agree with this definition: http://en.wikipedia.org/wiki/Side_effect_(computer_science) 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: http://en.wikipedia.org/wiki/Cohesion_(computer_science) http://en.wikipedia.org/wiki/Cohesion_(computer_science)