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.

side-effects
Filter by
Sorted by
Tagged with
1 vote
2 answers
48 views

scheme: element not removed after for-each / delete

Using the mit-scheme interpreter (v10.1.5-1), I was expecting this loop to remove each element of 'ls' except '2': 3 error> (define ls '(1 2 0 5)) ;Value: ls 3 error> (for-each (lambda (n) (delq!...
Francois's user avatar
  • 2,047
0 votes
1 answer
50 views

Is there a way to avoid using side effects to process this data

I have an application I'm writing that runs script plugins to automate what a user used to have to do manually through a serial terminal. So, I am basically implementing the serial terminal's ...
gfree's user avatar
  • 489
6 votes
3 answers
5k views

What is a "side-effect" in Scala?

I'm currently learning about functional programming using Scala. I'm also learning about loops and how they should be avoided due to side-effects. What does this mean?
ebeb9's user avatar
  • 1,029
0 votes
0 answers
124 views

Is (++x > ++x) well-defined in c++?

I read a bit about undefined behavior regarding side-effects and sequence points and their replacement in C++11. (Undefined behavior and sequence points) It raised the following question. Does this ...
Gonen I's user avatar
  • 5,727
0 votes
0 answers
94 views

SML/NJ : Calling function directly, versus using "val _ = fn...."

A content question (not a homework question) from a Coursera course on programming languages (taught at U of Washington) - I'm getting no response on the Coursera forum.... Abridged code (variable '...
JayW's user avatar
  • 23
1 vote
3 answers
343 views

duplication of terra rasters and side effects

When modifying some of the attributes of a duplicated SpatRaster, the original is also modified: library(terra) r <- rast(ncol=2, nrow=2, vals=c(5.3, 7.1, 3, 1.2)) #class : SpatRaster #...
Jean-Luc Dupouey's user avatar
1 vote
1 answer
198 views

Would using a global function like Object.keys() inside a pure function be reasonably considered an impurity?

I'm currently going through my React project looking at where I can convert impure functions into pure functions in order to have less side effects, tidier and more understandable code. I believe/hope ...
daniel blythe's user avatar
2 votes
1 answer
276 views

Controlling side-effects in function

I suppose most purely functional programming languages have feature to control side-effects in function, such like monads in Haskell, but Elm doesn't require such feature due to TEA. Moreover, I hear ...
Akihito KIRISAKI's user avatar
4 votes
4 answers
175 views

Unexpected result for predicate nb_setarg/3

Does anyone know the reason why predicate nb_setarg/3 does not work correctly when used with the predicate forall/3 in the toplevel of the SWI-Prolog interpreter (v. 8.2.1)? How it works when used in ...
slago's user avatar
  • 5,330
8 votes
2 answers
13k views

Pytest: Mock multiple calls of same method with different side_effect

I have a unit test like so below: # utilities.py def get_side_effects(): def side_effect_func3(self): # Need the "self" to do some stuff at run time. return {"...
user1452759's user avatar
  • 9,182
0 votes
1 answer
234 views

Add a side-effect to a function in a generic way

How can I write a Kotlin generic function that takes a function as an argument and adds a side-effect to it? For instance, fun something(one: Int, two: String): String { return "${one}, ${two}&...
digory doo's user avatar
  • 2,133
1 vote
0 answers
51 views

Can impurity affect the associativity of an operation?

Associativity is a desirable property and quite common for many operations in FP. Now I was wondering if an impure function can interfere with it. The only example I found isn't really convincing, ...
user avatar
0 votes
0 answers
93 views

What difference does it make if we don't perform the same side-effects after every re-render in React class component?

I came across this class component with 2 lifecycle methods handling the component's side-effects after each re-render: componentDidMount and componentDidUpdate I copied the example (at the bottom) ...
Eddie Lam's user avatar
  • 589
5 votes
2 answers
757 views

Can I tell my compiler to ignore the side effects of a statement or a function?

Suppose my code has the following function: inline int foo() { bar(); int y = baz(); return y; } and suppose that bar() and baz() have side-effects. If I write: int z = foo(); printf(&...
einpoklum's user avatar
  • 124k
2 votes
2 answers
1k views

What is a side effect in C?

In C99 clause 5.1.2.3 paragraph 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 ...
op ol's user avatar
  • 725
1 vote
4 answers
678 views

Generate random number with no side effect

Recentely I began to study functional programming paradigm using Scala as reference language. I come up with this problem: How to generate a random number with no side effect ? Googling I found this ...
giuseppe maugeri's user avatar
2 votes
0 answers
764 views

How to patch function's return value, but still get it's side effects in python unittest

I want to patch a function's return value in a unittest (it is originally expensive to evaluate), but still test its side effect (setting an attribute). The code looks sth like this: class MyClass: ...
arnoldlayne's user avatar
1 vote
2 answers
661 views

Is changing an object's variable outside of the object considered a side effect?

I'm trying to understand functional vs object-oriented programming. What I'm currently trying to understand is this notion of side effects in object-oriented programming, particularly as it pertains ...
mczarnek's user avatar
  • 1,355
1 vote
0 answers
82 views

webpack sideEffects list not work in server, But it's ok in my local machine

I am trying to use Tree Shaking in my project. And some code had side effects, So I set the under Array. It work well in my local,But It not work in my romate server,It will shaked all file. { "...
chao feng's user avatar
4 votes
1 answer
59 views

How to define a function that takes an argumente outside the paranthesis like names()

today I came across a question. Normaly every function in R takes arguments within its belonging paranthesis, e.g. # function definition f <- function(arg){print(arg)} # function call f(arg = 3) ...
Phil's user avatar
  • 59
0 votes
1 answer
544 views

Constexpr functions not called at compile-time if result is ignored

I was investigating some rather weird code-coverage results of constexpr functions (compile-time calls can't get instrumented by the code-coverage tool I use), and noticed that some constexpr ...
Sean's user avatar
  • 453
1 vote
0 answers
18 views

CSS filter property changes height of inner DIV [duplicate]

I have noticed that setting the CSS filter property affects the height of a child div under certain circumstances. My child div needs to be position: fixed; and height: 100%; In combination with the ...
cis's user avatar
  • 1,303
8 votes
1 answer
10k views

Handling API calls using useEffect vs using useCallback

This is very likely a dumb question -- I have the understanding that anything that triggers a side-effect should be handled with useEffect. I was wondering if that understanding is correct. ...
Eddie Lam's user avatar
  • 589
1 vote
0 answers
93 views

Possible side effects changing "normal" code with anonymous function

I must change some code in a big legacy application. Some portions of code must be replaced with a call inside an anonymous function. How sure can I be that I will not suffer side effects? The change ...
Iker's user avatar
  • 41
7 votes
2 answers
1k views

Dealing with type changing side effects in TypeScript

This is more of an open Question on how to deal with functions that have type altering side effects in TypeScript. I know and strongly agree with the notion, that functions should have as few side ...
Aram Becker's user avatar
  • 2,075
0 votes
1 answer
137 views

When do Applicatives run their effects?

Under "Why do Static Arrows generalise Arrows?" post, we often spoke of Applicative running side-effects before the application of the function-in-the-functor to the value-in-the-functor. ...
Zhiltsoff Igor's user avatar
3 votes
0 answers
103 views

Abusing unsafePerformIO to catch partial functions

So it occurred to me today that I could perform a little trick. {-# LANGUAGE TypeApplications #-} import Control.Exception import System.IO.Unsafe catchPartial :: a -> Maybe a catchPartial x = ...
Silvio Mayolo's user avatar
1 vote
1 answer
120 views

What are the function-call/procedure-call pairs in GAP?

By function-call/procedure-call pairs, I mean pairs of functions that do the same thing, except one returns it's result whereas the other alters it's argument(s) to be the result. For example the pair ...
Mike Pierce's user avatar
  • 1,504
1 vote
1 answer
538 views

Logging without side effects

I have a Scala package, that should be logged from top to bottom although I want it to be purely functional. Is there any way to implement logging without breaking functional style?
Nurgling96's user avatar
1 vote
0 answers
296 views

In MobX, why are side effects bad in render functions

Recently I was asked: Why can't I write to mobx state in a render function I know Mobx disallows it, and it isn't good, however I also know you can get around Mobx's check simply by waiting a bit, ...
yeerk's user avatar
  • 2,315
3 votes
1 answer
286 views

boolen expression and side effects

I hope everyone is safe. I am learning Haskell and came upon the fact that a function in Haskell has no side-effect. I just wondered in imperative languages are boolean expression considered to be ...
ZeevKeane's user avatar
3 votes
3 answers
7k views

What is side effect in C?

Wikipedia says that: In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment, that is to ...
Ulaş Sezgin's user avatar
0 votes
2 answers
81 views

Are there any languages that handle functional impurity (side effects) without modeling them as RealWorld or IO?

One thing that always bothered me in Haskell (and other functional languages, for that matter) is that the entire language is pure, but side-effects are indirectly allowed by using an object that ...
user3F31A28's user avatar
2 votes
0 answers
149 views

Does Sphinx natively support documentation on side-effects?

Other documentation tools support specific tags in order to document side-effects (such as the @modifies tag in JSDoc, for example). I was wondering if Sphinx or any plugin may offer something similar,...
hblanco's user avatar
  • 126
-1 votes
1 answer
131 views

bash: assignment AND condition test in nested statement?

What I'm looking for is a compact line of code that uses the value of an expression twice in one nested statement for an assignment to a variable and a condition test of the variable's new value ...
xinul's user avatar
  • 3
0 votes
3 answers
45 views

Why this python code occurs the side-effect?

def to_un(g): un = [] for v in g: un.append(v) print(g) for v in range(len(un)): for u in un[v]: if v not in un[u]: un[u].append(v) ...
Orange Square's user avatar
0 votes
1 answer
2k views

Can not implement callback inside of useFocusEffect from React-navigation

I have React-native app with topTabNavigator with three tabs. And usually componentDidMount and componentWillUnmount lifecycle methods don't work when the user changes the tab. Therefore instead of ...
jocoders's user avatar
  • 1,774
4 votes
1 answer
436 views

PureScript equivalent to ‘error’ from Haskell prelude

I’m new to PureScript and trying to find the idiom for “assertion failure”. I use this commonly to halt execution when: an invariant I need to rely on is broken a branch of the code is unreachable I ...
Roly's user avatar
  • 2,174
-1 votes
1 answer
86 views

Side effect in different programming language [closed]

I am studying the Side Effect for different programming language. For instance, in C++, if I define x = 1; int f(int y) { x = x + y; return x; } and execute f(1) the new value of x is equal ...
J.G's user avatar
  • 197
5 votes
1 answer
839 views

What is Local Reasoning , exactly?

What is Local Reasoning ? how does it relate to Referential Transparency, Equational Reasoning and Laziness ?
Ashkan Kh. Nazary's user avatar
2 votes
0 answers
67 views

Which sorts of side effects are caused by mutations? [closed]

Mutable data types cause side effects, but what side effects specifically and how can they be grouped? So far I've found two sorts of effects: race conditions (due to single threaded JS in the ...
user avatar
0 votes
2 answers
296 views

Why is this java code not producing the result I am expecting?

The program needs to issue the correct ticket price based on the age and gender of the customer. import java.util.Scanner; public class Main { public static void main(String[] args) { ...
Rajsh's user avatar
  • 21
6 votes
2 answers
3k views

Why should we avoid side-effects in components constructors?

I wonder if there is a good reason not to send requests in the constructor of a component instead of in its componentDidMount hook? I've seen some interesting (but a bit incomplete) answers for: is it ...
cglacet's user avatar
  • 9,904
0 votes
1 answer
39 views

Are side effects always visible in task continuations?

Are side effects guaranteed to be visible in task continuations? object o = null; Task.Run (() => o = new object ()) .ContinueWith (t => o.ToString ()); The continuation may run on a ...
mafu's user avatar
  • 32.3k
3 votes
1 answer
181 views

How to limit expression access to types external in Roslyn?

So I read thru the ways of how to evaluate expressions with Roslyn and I wonder if it is possible and how to limit expression to a set of basic math operations and operations on a reduced set of types ...
DuckQueen's user avatar
  • 862
0 votes
1 answer
322 views

How to check if a function has no side-effects (is pure) at runtime?

So say we have loaded a function F that take in/out a set of args and returns a result. How to check at runtime if this F does not act on anything other than args members and functions? Meaning no ...
DuckQueen's user avatar
  • 862
2 votes
1 answer
352 views

Mock instance method of a model class by replacing it with a new method

I want to replace the instance method "set_email_id" with a new function in unit tests by mocking. The instance method returns the email_id field but I want a new function to print the same field. I ...
CemreY's user avatar
  • 384
1 vote
3 answers
865 views

How can I communicate to the user's browser that a POST request it made is side-effect-free?

I have to add a page to my website that will be accessed via a POST request. The request is side-effect-free, hence it is safe for the user to use their browser's "Refresh" button on the page. The ...
Hammerite's user avatar
  • 22.1k
3 votes
0 answers
332 views

In R, can you force foreach to have only side effects?

I'm parallelizing a loop that creates a relatively large dataset at each iteration. I'm using foreach::foreach() along with the doParallel backend. When I use foreach the standard way, my RAM usage ...
Ben's user avatar
  • 459
11 votes
2 answers
3k views

Saving to database in stream pipeline

As per the documentation on Oracle's website: Side-effects in behavioral parameters to stream operations are, in general, discouraged, as they can often lead to unwitting violations of the ...
Titulum's user avatar
  • 10.8k

1 2
3
4 5
10