Questions tagged [side-effects]

A side-effect is a programming term that refers to intended changes in the program behavior, such as a variable changing value. It is in important term when discussing compiler optimization and expression evaluation.

A side-effect is a programming term that refers to intended changes in the program behavior, such as a variable changing value. It is in important term when discussing compiler optimization and expression evaluation.

Most notably, this term is often used in the C and C++ languages. One formal definition of the term can be found in ISO 9899:2011 (C11) 5.1.2.3 §2:

Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression in general includes both value computations and initiation of side effects.

C++ contains an identical definition, see for example C++11 1.9/12.

When a compiler optimizes code, it has to ensure that it removes no side effects (C11 5.1.2.3 §4):

In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object).

Therefore the volatile qualifier is often used to prevent the compiler from optimizing cerain parts of the code, since any access (read/write) to a volatile object is considered a side effect.

Side effects is also an important term when discussing expression evaluation. For example, expressions that contain multiple side effects on the same variable, with no so-called "sequence point" in between, invokes undefined behavior, see Undefined behavior and sequence points.

461 questions
0
votes
1 answer

Side-effects: Is modifying local variables an external or internal effect?

I am learning about side-effects in functional programming. I know that external effects are effects that are observable outside the function, whereas internal effects are not visible from the outside. I would like to know whether modifying local…
ceno980
  • 2,003
  • 1
  • 19
  • 37
0
votes
1 answer

How do I get a redux-saga generator to 'take' an action and also return the results?

The fetchBooks generator function takes the action and fetches books per the category specified. function* fetchBooks() { while (true) { const { payload:{ bookCategory }} = yield take(FETCH_BOOKS); // receive and perform external fetch …
M.Holmes
  • 403
  • 1
  • 7
  • 22
0
votes
3 answers

How to return a Mono (as a side effect?) of Mono.subscribe()?

I have the following code, which "works"...so far. By "works", I mean that the Flux is being returned by service.getAll(), and the "hasElements().subscribe(this::foo)" results in foo() generating output that correctly reflects whether the…
SoCal
  • 801
  • 1
  • 10
  • 23
0
votes
1 answer

Delete Certificate From Azure Key Vault? Does this delete Cert Resource types?

I have a certificate that needs to be deleted. But it is currently assigned out to several Microsoft.Web resources. When the cert was assigned, Microsoft.Web/Certificate resources were created. My question: When I use the Delete Certificate command,…
Itanex
  • 1,664
  • 21
  • 33
0
votes
2 answers

recursion problem in parsing with RapidXML/C++ class pointers side-effect

I want to share this odd but interesting situation I stumbled upon recently while trying to use RapidXML for XML parsing in C++. I wanted to write a recursive function to search and return a particular node among the children of a given node. My…
ascanio
  • 1,506
  • 1
  • 9
  • 18
0
votes
1 answer

Side effect of casting to a list?

I have a list of (x,y) tuples ("lt" in the example, below). I want to extract the x's and y's so I can perform a Pearson correlation calculation. If I execute this code: lt = [(1,2), (3,4), (5,6)] print(lt) unzip_list = zip(*lt) xs =…
JGV
  • 163
  • 3
  • 14
0
votes
1 answer

Cancel request using redux observable is not working

I'm trying to add in canceling in my request using redux-observable. Trying to implement a simple login example. Currently, I am unable to submit the login request again after I added the cancelation. const loginUserApiCall = (username, password)…
fscore
  • 2,567
  • 7
  • 40
  • 74
0
votes
2 answers

statsd's side effects possibly causing extra latency

I'm using Datadog's statsd client to record the duration of a certain server response. I used to pass in quite a few number of custom tags when time-ing these responses. So I'm in the process of reducing the number of custom tags. However, the…
sshh
  • 5,964
  • 4
  • 17
  • 20
0
votes
0 answers

Can Docker Image compilation have side effects?

Is it safe to build Docker Images based on untrusted code on my server? I know that running the resulting Images is safe (in so far as something this complicated can ever be truly safe), but can building them have side effects?
Florian Dietz
  • 877
  • 9
  • 20
0
votes
1 answer

C for loop has different effect than rolled out loop

I am writing a simple queue in c using a linked list that keeps track of the last element. This is my code: #include #include #include #include typedef struct node_s { uint32_t x, y; } node; //…
Matthias
  • 737
  • 8
  • 14
0
votes
2 answers

What can go wrong if operators have side-effects?

I came across a Python library that defines a class analogous to the following, where the >> operator is overloaded to have a global side-effect: from collections import defaultdict class V(object): """A Vertex in a graph.""" graph =…
Aaron Voelker
  • 729
  • 6
  • 12
0
votes
1 answer

How to test effects in ngrx?

I just want to get my getUser effect below. I'm using angular5, typescript and ngrx. I'm open to alternative examples to what I have below. This is my effect: import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/catch'; import { Effect,…
AngularM
  • 15,982
  • 28
  • 94
  • 169
0
votes
1 answer

Argument input and sideffect in subclass method

It's about the following situation: public class A { int x=3; public A() { setX(x-3); } void setX(int z) { this.x = z; } } public class B extends A { static int x = 7; void setX(int z) { x = z; …
Karl
  • 63
  • 6
0
votes
2 answers

Side Effects in Go Language

Does anyone know how to write a function with side effects in the Go language? I mean like the getchar function in C. Thanks!
AHS
  • 774
  • 1
  • 10
  • 17
0
votes
2 answers

how to check is the data finished update then do other thing (REACTJS + REDUX)

Now I check by using 'componentWillRecieveProps' to check 'nextProps' of Redux state is it finish or not. like this example, if (!nextProps.a.update && !nextProps.a.error && nextProps.a.update !== this.props.a.update) { const oldData =…
ppppp
  • 199
  • 1
  • 2
  • 15