Questions tagged [side-effect]
The side-effect tag has no summary.
50 questions
11votes
4answers
1kviews
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 ( ...
0votes
2answers
220views
Intuition behind why Rust's io::stdin().read_line() relies on a side effect?
I'm reading the second chapter of the official Rust book as a pretty seasoned python programmer. As you can imagine, its been pretty jarring, but I'm learning. My specific question is about whether or ...
15votes
4answers
4kviews
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 ...
10votes
6answers
5kviews
If a function mutates outer state during execution but reverts the outer state into original state after execution, does it still contain side effect?
According to What is a "side effect?", I know the side effect means changing outside world. But what if a function that changes the outside state during execution, but reverts the state to ...
1vote
5answers
833views
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 ...
3votes
1answer
209views
How to handle a state machine side effect being optional?
I have a state machine that, as a side effect of going into a certain state, sends a message to a remote server. In some situations, however, I don't want the state machine to send that message, even ...
0votes
3answers
810views
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 ...
17votes
5answers
6kviews
Is there a non-deterministic function without side effects?
By definition, a pure function is deterministic + no side effect. Is there any example for a function which has no side effects, but is non-deterministic? I.e., a function without side effects, but ...
0votes
1answer
1kviews
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: ...
-4votes
2answers
138views
Does the HTTP specification fully define the semantics of request methods?
I see two possible interpretations of the semantics of request methods defined in the HTTP specification RFC 7231: The intended effect of a request method is fully defined by the HTTP specification (...
0votes
2answers
243views
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", "...
3votes
2answers
473views
Is rebooting a server idempotent or not?
In his article RESTful Casuistry, Tim Bray claims that rebooting a server is not idempotent: But I don’t buy it, and here’s why. If I want to update some fields in an existing resource, I’m inclined ...
2votes
1answer
402views
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 ...
1vote
1answer
1kviews
Is having side-effects in constructor an anti-pattern?
I was trying to understand how to embed v8 engine in a C++ application and was trying to understand the following hello world problem as a result. I found the code to be unreadable at first glance. e....
1vote
2answers
521views
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 ...