Skip to main content

Questions tagged [side-effect]

The tag has no usage guidance.

15 votes
4 answers
4k 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 ...
Kaia's user avatar
  • 422
10 votes
6 answers
5k views

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 ...
wcminipgasker2023's user avatar
1 vote
5 answers
611 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 ...
wcminipgasker2023's user avatar
3 votes
1 answer
167 views

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 ...
PieterV's user avatar
  • 215
0 votes
3 answers
568 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 ...
PieterV's user avatar
  • 215
17 votes
5 answers
6k views

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 ...
Helin Wang's user avatar
0 votes
1 answer
920 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: ...
pob's user avatar
  • 109
-4 votes
2 answers
135 views

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 (...
Géry Ogam's user avatar
0 votes
2 answers
231 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", "...
Géry Ogam's user avatar
3 votes
2 answers
455 views

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 ...
Géry Ogam's user avatar
2 votes
1 answer
334 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 ...
Olle Härstedt's user avatar
1 vote
1 answer
1k views

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....
Anurag Kalia's user avatar
1 vote
2 answers
495 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 ...
Olle Härstedt's user avatar
2 votes
2 answers
694 views

What's the value of IO Monad?

When I'm writing code in the form of IO Monad, I wonder what's real value of it.For example I have a function as def something(in: In): IO[Out]; my function is a pure function that **returns an impure ...
Reza Same'ei's user avatar
8 votes
3 answers
894 views

Avoiding side effects in immutable class constructor

I rewrote a very long method in which some data is queried from a database, based on info about a particular account, which is queried first. I split out the account info into an immutable inner ...
jbruenker's user avatar

15 30 50 per page