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 ...
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 ...
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: ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pure-function × 41functional-programming × 23
c# × 8
side-effect × 6
object-oriented × 4
design × 3
design-patterns × 3
imperative-programming × 3
javascript × 2
object-oriented-design × 2
functions × 2
composition × 2
scope × 2
architecture × 1
algorithms × 1
unit-testing × 1
.net × 1
c × 1
coding-style × 1
terminology × 1
naming × 1
dependency-injection × 1
language-agnostic × 1
coding-standards × 1
history × 1