Questions tagged [side-effect]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
2answers
245 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 ...
1
vote
1answer
136 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
1answer
489 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....
1
vote
2answers
239 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 ...
1
vote
2answers
230 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 ...
7
votes
3answers
547 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 ...
0
votes
1answer
246 views

Side-effect-free functions and returning domain information DDD

In Domain-Driven Design (Eric Evans) the discussion on side-effect-free functions talks about separating commands which "result in modifications to observable state" from queries which have no side-...
0
votes
1answer
87 views

Where to store side effect state in an event sourcing system

I also had a look at How do I deal with side effects in Event Sourcing? but the solution wasn't clear to me. If I store "EmailSent" event in the event stream, I might issue the external request to ...
0
votes
3answers
311 views

Side-effect free programming language for reproducible data transformation

Is there a usable programming language that disallows all side effects except for its input stream (aka STDIN) and its output stream (aka STDOUT)? All executable scripts in the language should be ...
1
vote
1answer
160 views

best practice for data.table use in “formal” code

Consider a "large-ish" data set (~2-5M rows) that goes through multiple stages of cleaning/processing: library(dplyr) largedat %>% mutate( # overwrite v1 based on others v1 = somefunc(...
10
votes
2answers
3k views

Do functional programming languages disallow side effects?

According to Wikipedia, Functional programming languages, that are Declarative, they disallow side effects. Declarative programming in general, attempts to minimize or eliminate side effects. Also, ...
45
votes
9answers
12k views

Return considered harmful? Can code be functional without it?

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. But this ...
6
votes
4answers
4k views

Does object-oriented programming allows side effects and state changes?

I know that obviously every language has its own characteristics and implementations, but from a theoretical standing point, viewing OOP as an abstract programming paradigm, does it allows side ...
8
votes
6answers
725 views

Why is it is easier to reason about programming languages and programs that have no side effects?

I read "The Why of Y" from Richard P. Gabriel. It is an easy to read article about the Y combinator, which is quite rare. The article begins with the recursive definition of the factorial function: ...
3
votes
0answers
166 views

Are there downsides to writing PDO/mysqli statements into my code directly vs using my own redirect wrapper methods?

TL;DR: To access DB functionality in my codebase I currently use a custom layer throughout the code. The layer needs an upgrade in order to begin accepting prepared statements, which it currently ...
44
votes
7answers
16k views

What do you call a function where the same input will always return the same output, but also has side effects?

Say we have a normal pure function such as function add(a, b) { return a + b } And then we alter it such that it has a side effect function add(a, b) { writeToDatabase(Math.random()) return a ...
19
votes
4answers
2k views

Is the benefit of the IO monad pattern for handling side effects purely academic?

Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me. My (limited) understanding of functional programming is that state/side effects ...
13
votes
3answers
2k views

Origin of “a method should return a value or have side-effects, but not both”

I read once that a method should either have a return value (and be referentially transparent), or have side-effect(s), but not both. I cannot find any references to this rule, but want to learn more ...
1
vote
2answers
285 views

Are any side effects not concrete side effects?

In Chapter 23 of "Object Oriented Software Construction" (1988), Betrand Meyer makes a distinction between side effects, concrete side effects, and abstract side effects. Meyer defines a side effect ...
5
votes
1answer
741 views

Mutable with logic inside or immutable with logic outside?

I know immutable objects are preferred to mutable objects for reasoning and maintenance. But in occasions making a class immutable have some costs, let me explain it with a simple example: class ...
0
votes
1answer
69 views

Choose approaches for updating an object

Say I have a simple object created by from user input: var input = { url: 'http://example.com/', path: 'abc', user: 'adam' }; And I am to write function(s) that update url and path properties ...
8
votes
1answer
3k views

Functional programming for loop side effect

I am trying to get my head around as to why having a local variable or a for loop inside a function is not considered to be pure functional programming. Given this function: int as_int(char *str) { ...
9
votes
6answers
5k views

How can IO cause side effects in Functional Programming? [duplicate]

Whenever I read about Haskell, I find that IO can cause side effects. But I do not understand how it would do it? Do we mean that we are writing to a file from one lazy sequence and another lazy ...
18
votes
5answers
4k views

Why is reading from memory not a side-effect but reading from a file is?

What does exactly make reading from the process memory a pure operation? Suppose I created an array of 100 integers in the global memory and then took the 42th element of this array. It is not a side ...
7
votes
2answers
2k views

Alternative to language purity

Purity One of the interesting concepts in Haskell is the purity. However, I am wondering what the pragmatic reasons behind this is - let me explain a bit more before you reject my question. My main ...
10
votes
4answers
840 views

Is it ever OK for a conditional to have side effects? [closed]

I'm taking intermediate data structures course as a prereq for entry into the CS MS program at a University everyone in America has heard of. One line of code that was written in class caught my eye: ...
5
votes
2answers
760 views

Can referentially transparent functions have side effects?

I read everywhere that referential transparency and side-effects are mutually exclusive for all functions, however, what about the case in which a function changes some state that has no effect on its ...
11
votes
3answers
2k views

Side Effects Breaking Referential Transparency

Functional Programming in Scala explains a side effect’s impact on breaking referential transparency: side effect, which implies some violation of referential transparency. I’ve read part of SICP, ...
10
votes
2answers
2k views

Unit testing side effect-heavy code

I'm starting to write C++ code to run a robot, and I don't know how to incorporate unit testing, if indeed I can. I have been provided with a library which allows the creation of "commands" ...
16
votes
2answers
533 views

Side effect-free interface on top of a stateful library

In an interview with John Hughes where he talks about Erlang and Haskell, he has the following to say about using stateful libraries in Erlang: If I want to use a stateful library, I usually build ...
10
votes
2answers
809 views

Where do we put “asking the world” code when we separate computation from side effects?

According to Command-Query Separation principle, as well as Thinking in Data and DDD with Clojure presentations one should separate side effects (modifying the world) from computations and decisions, ...
8
votes
3answers
2k views

How is referential transparency enforced?

In FP languages, calling a function with the same parameters over and over again returns the same result over and over again (i.e. referential transparency). But a function like this (pseudo-code): ...
9
votes
2answers
3k views

Are side-effects in Array's “every”, or “some” bad?

I've always been taught that having side-effects in an if condition are bad. What I mean is; if (conditionThenHandle()) { // do effectively nothing } ... as opposed to; if (condition()) { ...
1
vote
2answers
508 views

I don't understand the definition of side effects [duplicate]

Possible Duplicate: What is a “side effect?” I don't understand the wikipedia article on Side Effects: In computer science, a function or expression is said to have a side effect if, in ...
29
votes
3answers
6k views

Different ways to see a monad

While learning Haskell I have faced a lot of tutorials trying to explain what are monads and why monads are important in Haskell. Each of them used analogies so it would be easier to catch the meaning....
7
votes
6answers
696 views

Does long term programming affect writing in a native spoken languages? [closed]

So, I am getting some years under my belt in long term programming. I have noticed, however, when the frequency and duration started increasing in my coding sessions that when I actually went to ...
15
votes
5answers
2k views

How to create scalable & side-effect free integration tests?

In my current project, I am having a hard time coming up with a good solution to create scalable integration tests that have no side effects. A little clarification on the side effect free property: ...
31
votes
5answers
6k views

Asynchronous Programming in Functional Languages

I'm mostly a C/C++ programmer, which means that the majority of my experience is with procedural and object-oriented paradigms. However, as many C++ programmers are aware, C++ has shifted in emphasis ...
74
votes
14answers
28k views

Why are side-effects considered evil in functional programming?

I feel that side effects are a natural phenomenon. But it is something like taboo in functional languages. What are the reasons? My question is specific to functional programming style. Not all ...