Skip to main content
14 votes
Accepted

Can functional programming languages have deadlock conditions?

The quote is correct in principle. If you don't have any mutable state or side effects then you don't need to lock anything and without locks you don't get deadlocks. But in reality, most programs, ...
JacquesB's user avatar
  • 62.3k
12 votes

Should I expose an instance's state with methods?

It seems upon updates by the OP that I glommed onto the wrong part of the text and the CQS aspect of this is not terribly relevant to the real question. I'm going to leave the original answer since it ...
JimmyJames's user avatar
  • 30.9k
12 votes

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

The video you cited is for an advanced and expert audience. Herb Sutter tries to bring this audience to a consensus on how to best communicate the intent of these keywords to other people, in this age ...
rwong's user avatar
  • 17.2k
10 votes
Accepted

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

Mutable: public void DoubleArray(int[] array) { for (int i=0; i<array.length; i++) array[i] *= 2; } Immutable: public int[] DoubleArray(int[] array) { int[] result = new int[array....
Robert Harvey's user avatar
8 votes

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

Here's what most people seem to miss about immutability. Consider the following function: def factorial(n: Int): Int = if (n == 0) 1 else n * factorial(n - 1) This function is completely immutable. ...
Karl Bielefeldt's user avatar
7 votes

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

Is it good practice while designing a thread-safe application to mark every member function const and every member variable mutable? No, that is not good practice. A const member function signals ...
Bart van Ingen Schenau's user avatar
6 votes
Accepted

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

Global state is not necessarily evil, even in functional languages. However: all this does is enforce a consistent ID generation per process. Multiple processes could still clash. You have to decide ...
amon's user avatar
  • 136k
5 votes

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

Mutable member variables are useful if a class wants to save internal data, and the content is not relevant to the status of the class as seen from the outside (its user). There are many situations ...
Aganju's user avatar
  • 1,473
5 votes
Accepted

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

I think you have this backwards. The only thing that private void normalizeDimensions(Request request); can do is to modify the object (or have other side effects), so it's clear that's what this ...
Philip Kendall's user avatar
5 votes
Accepted

Would an mutable to immutable transpiler be possible?

No, this is not possible in the general case since the data dependencies in a system can be very tricky. As a simple example, consider the following setting: var person = {...}; var someOtherObject = {...
amon's user avatar
  • 136k
4 votes

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

You are correct that perfectly immutable program, one that relies only on it's input when started wouldn't be much useful. But the idea of immutability is not to make program completely immutable, it ...
Euphoric's user avatar
  • 38.2k
4 votes

Should I expose an instance's state with methods?

Should you use methods over properties? Properties are kind of methods already. But, practically, if you do this you will run into problems with serialisation libraries and the like (vue observables) ...
Ewan's user avatar
  • 84.4k
2 votes

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

In the functional world Philip Kendall is entirely correct. And in the OOP world we occasionally write functional code as well. So if you're going to make Request immutable then: private Request ...
candied_orange's user avatar
1 vote

How to avoid global mutable variables within a class?

tl;dr– If you need to share a mutable state between different methods in the same class, then having that mutable state stored in a field/property seems entirely reasonable. However, you may ...
Nat's user avatar
  • 1,101
1 vote

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

@Aganju has given some good examples. I'm just going to add one more, but with a substantial difference. The examples s/he gave were of cases where a class might reasonably consider using a mutable ...
Jerry Coffin's user avatar
  • 44.8k
1 vote

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

As already stated by others, a const function implies it should be thread-safe to call it from multiple threads simultaneously, without calling a non const function at the same time. As Herb Sutter (...
m7913d's user avatar
  • 111

Only top scored, non community-wiki answers of a minimum length are eligible