Skip to main content

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
9 votes
6 answers
4k views

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
227 views

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
  • 19.1k
1 vote
3 answers
323 views

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 ...
CPlus's user avatar
  • 8,261
20 votes
6 answers
8k views

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
14 votes
5 answers
711 views

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,047
8 votes
3 answers
353 views

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