Questions tagged [side-effect]
The side-effect tag has no summary.
50 questions
11 votes
4 answers
1k views
Is it OK for a function to both do-something and return-something?
Is it OK for a function to both do-something and return-something? I try to avoid it for the most part, but there are situations where trying to avoid it would lead to worse/less clean code. Ex: if ( ...
15 votes
4 answers
5k views
What side-effects, if any, are okay when importing a python module?
Generally, modules should not have side effects. However, in a lot of cases, the side-effects are hard to avoid or may be desirable. There are also popular packages with on-import side-effects. Which ...
1 vote
5 answers
941 views
Should I repeat calculations twice to follow "return a value or have side-effects, but not both"?
According to Origin of "a method should return a value or have side-effects, but not both", a method should either return a value or have side-effect, but not both. However, I often see some ...
0 votes
3 answers
968 views
How to implement state machine side effect that needs data the state machine doesn't have
Given a state machine that implements a certain protocol. I need multiple instances of this protocol running, so I create multiple instances of this state machine. Each instance is associated with a ...
0 votes
1 answer
1k views
How to test a function with several conditional nested side effects
In Python, consider a function like the following: def main(*args): value1 = pure_function1(*args) if condition(value1): value = side_effect1(value1) if value: ...
0 votes
2 answers
263 views
A command as the intended effect of POST versus as the side effect of PUT
The intended effect (semantics) of the POST method is resource specific, e.g. executing a command with arguments: POST /command HTTP/1.1 {"parameter-1": "argument-1", "...
2 votes
1 answer
444 views
Can I enforce "functional core, imperative" shell with a framework?
The design pattern known as "functional core, imperative shell" is about separating side-effects from pure calculations, where business logic is supposed to be pure and then coordinated by ...
1 vote
2 answers
541 views
Remove all side-effects from business logic
I'm looking for feedback for a design pattern that aims to remove all side-effects from business logic. I'm using PHP but the pattern can be applied to any OOP language. The point is to enforce pure ...