7 votes

Should I repeat calculations twice to follow "return a value or have side-effects, but not both"?

The trouble with trying to follow everybody's idea of what is good coding principles is that you end up unable to actually write anything without violating at least one of those principles. Repeating ...
Simon B's user avatar
  • 9,631
1 vote

Function objects with no state shouldn't be object oriented?

The premise is just wrong. It is fine to have object with no internal state and can be perfectly "object oriented". A common example is in the Strategy pattern, where the strategy-object ...
JacquesB's user avatar
  • 59.6k
1 vote

Should I repeat calculations twice to follow "return a value or have side-effects, but not both"?

You can follow the principle easily, and still don't have to run or implement the operation twice, by using an object encapsulating the operation: sorter = { stepCount: -1, customSort: ...
Doc Brown's user avatar
  • 207k
1 vote

Origin of "a method should return a value or have side-effects, but not both"

This is just unclear. I have a database. There’s a command “remove all records with property x”, that’s the first category. There’s a query “how many records are there with property x”, which is the ...
gnasher729's user avatar
  • 45.2k

Only top scored, non community-wiki answers of a minimum length are eligible