Questions tagged [immutable]

For questions about designing languages where data values are immutable and cannot be changed, or implementation aspects specifically related to immutability

Filter by
Sorted by
Tagged with
8 votes
5 answers

Would it be safe to introduce the "freeze" statement?

Would it be safe to introduce the freeze statement for freezing a mutable object into an immutable object? Such statement would mix well into dynamically-typed ...
Dannyu NDos's user avatar
9 votes
0 answers

How can a compiler optimise persistent data structures to use mutable data structures "under the hood"?

Consider for a motivating example a copy-on-write array, which implements a persistent (i.e. immutable) array data type. As an optimisation at runtime, a reference counter can be used to avoid the ...
kaya3's user avatar
  • 17.6k
1 vote
3 answers

Is there any way a Java-like language could implement immutable primitive arrays without incurring performance penalties?

I asked: What prevents Java from having immutable primitive arrays? a while back and got an answer: Because immutable primitive arrays would typically require checking some immutable flag every time a ...
user16217248's user avatar
  • 7,535
20 votes
6 answers

Why do some languages have both immutable "variables" and constants?

Some programming languages (Rust is one I can think of off the top of my head) provides mechanisms to have immutable variables but they also have constants. Isn't an immutable variable just a constant?...
QAH's user avatar
  • 311
13 votes
5 answers

What are the advantages and disadvantages of immutable languages?

This means variables can't be overwritten, arrays can't be modified, and nothing can be modified "in-place" - a new variable has to be created. Or if you need to modify it with a loop, then ...
naffetS's user avatar
  • 1,027
8 votes
3 answers

What are the downsides of making all strings immutable to improve security and concurrency?

Many programming languages (such as Java) make strings immutable to mitigate many potential serious security threats. Are there any major downsides or issues with a language having all strings ...
James Risner's user avatar