Skip to main content

Questions tagged [mutable]

4 votes
2 answers
2k views

Should I expose an instance's state with methods?

I've read somewhere about a pattern that is as follows: if it'll change the state of the instance, the method should be named with a verb and return void; and if the method just returns something (...
Bernardo Benini Fantin's user avatar
4 votes
2 answers
3k views

Should a method modifying object passed as a parameter return the modified object? [duplicate]

I have some incoming request - it's an instance of class generated from api specification - POJO with public getters/setters. I would like to normalize some values. For example dimensions (to use ...
Shaolin's user avatar
  • 43
2 votes
0 answers
119 views

Should the usage of an needlessly mutable type by pointed out in code reviews, even when multi-threading is not a concern? [closed]

None of my team's programs care about multithreading, parallelisation, async, or anything else that benefit from immutability. However, immutability is clearly in fashion at the moment and I'm ...
J. Mini's user avatar
  • 1,015
7 votes
1 answer
534 views

Can functional programming languages have deadlock conditions?

I am reading through "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and it says that: All race conditions, deadlock conditions, and concurrent update problems are ...
Quantum Guy 123's user avatar
0 votes
1 answer
165 views

Would an mutable to immutable transpiler be possible?

I'm very new to writing immutable code. Would there be any fundamental issues trying to transpile arbitrary mutable code person.age = 20 into immutable code person = { ...person, age: 21 }? I am aware ...
phil-daniels's user avatar
5 votes
3 answers
736 views

How could a computer program do anything if everything is immutable?

I feel this is a bad question because I probably do not understand what I am talking about. In my effort to learn about functional programming, I became stumped on understanding the idea of immutable ...
Julian's user avatar
  • 77
0 votes
4 answers
802 views

How to avoid global mutable variables within a class?

I know the fact that global mutable variables are bad as they can be accidentally modified and make testing difficult. However, there are situations when a class needs to cache some information, for e....
Navjot Singh's user avatar
1 vote
2 answers
713 views

Is there a natural architecture design where I should use mutable member variable(c++)?

I have come across mutable variables kind often, yet it seems to me it's always been use to solve a problem of design(typically coping with legacy code) rather than to answer a natural, intrinsic ...
stackoverflower's user avatar
8 votes
4 answers
5k views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
CK.'s user avatar
  • 197
5 votes
1 answer
453 views

Is private global mutable state ever appropriate, namely when used to prevent API misuse?

I am writing a type checker for an ML dialect that involves generating "fresh" (new and unique) "type variables" (values representing unknowns). My strategy, and the strategy that seems to be used in ...
Del's user avatar
  • 161
5 votes
1 answer
2k views

How to properly extend an interface with immutable properties to offer mutability via another interface

The following code snippets are simplified to demonstrate the context! The actual interfaces and classes are POCOs having additional properties. The types are part of library I am working on, the ...
ckerth's user avatar
  • 51
0 votes
2 answers
117 views

Is it a different object or the same object with an altered property (mutable or not)?

When I design the architecture of an application, I usually think about the nature of the objects and the interactions between them. The way I currently think about mutability is to ask myself if ...
Paul92's user avatar
  • 2,631
6 votes
1 answer
7k views

Is it pythonic to use properties to limit the mutability of class attributes (variables and methods)?

Some Explanation I'm somewhat new to python and to programming (I've been at it for a little over a year). I just recently discovered python properties, and I've been using them to limit the ...
Josie Thompson's user avatar
0 votes
1 answer
164 views

Mutability, and pass-by-reference, "new" object, what am I having left out?

I started questioning what I know, or thought that I know, after this question: Array.fill differs from literal 2D definition on assignment A JavaScript question, defining an array with predefined ...
ASertacAkkaya's user avatar
59 votes
3 answers
44k views

Is it an antipattern to use peek() to modify a stream element?

Suppose I have a stream of Things and I want to "enrich" them mid stream, I can use peek() to do this, eg: streamOfThings.peek(this::thingMutator).forEach(this::someConsumer); Assume that ...
Bohemian's user avatar
  • 2,076

15 30 50 per page