# Why are strings immutable (historical records request)

**URL:** <https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115>\
**Category:** Community\
**Tags:** strings\
**Created:** [December 25, 2022, 9:50pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115 "2022-12-25T21:50:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [December 25, 2022, 9:50pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/1 "2022-12-25T21:50:27Z")

</div>

At some point it was decided that `String`s would be immutable in Julia. Is there a record of that conversation (e.g. a mailing list or GitHub thread)?

Failing that, is there a record of the conversations that led core language designers to decide to make strings immutable in another programming language?

---

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [December 25, 2022, 11:02pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/2 "2022-12-25T23:02:53Z")

</div>

Not quite what you’re looking for, but a starting point: [String should be officially immutable & "abc" === "abc" · Issue #22193 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/22193)

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [December 25, 2022, 11:20pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/3 "2022-12-25T23:20:39Z")

</div>

I think the person who knows the history of this decision best may also be @ScottPJones !

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 30, 2022, 1:42am UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/4 "2022-12-30T01:42:12Z")

</div>

See [https://groups.google.com/g/julia-dev/c/-u4k0xX5ziQ/m/jEV-Q2PBmw0J](https://groups.google.com/g/julia-dev/c/-u4k0xX5ziQ/m/jEV-Q2PBmw0J) … strings were treated as immutable from the earliest days of Julia, even though the language didn’t enforce this at first.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 12, 2023, 5:00pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/5 "2023-01-12T17:00:01Z")

</div>

I can’t find the origin in emails, but this was my decision, effected by not providing any mutating APIs to strings. [Here’s](https://groups.google.com/g/julia-dev/c/d90FrbXRObY/m/zabmcZ8lgW0J) an older more direct explanation of why from 2012:

> There’s an important psychological distinction between things we think of as mutable versus immutable: values that are _defined_ by their values should be immutable, whereas values that _contain_ other values but have an independent identity can be mutable. Numbers are a prototypical example of being defined by their values — if you change the imaginary part of a complex number, you have a different number, not the same number altered (it sounds weird to even talk about “altering” a number). Arrays are the prototypical containers: change the contents of an array all you want and it still has an independent identity (psychologically).
> 
> The reason I believe strings are so dangerous as mutable values in high-level languages is that we think of them as being defined by their value: the string “foo” and “fox” are simply different values, regardless of whether the former was altered into the latter using the same memory. However, as a legacy from the implementation and the fact that in C they are just arrays of bytes, a low-level view of them is as containers. In C that’s natural and fairly unsurprising because you’re used to thinking about the actual memory buffer that represents a string. In a higher level language, it’s really, really surprising when a string changes value because you passed it to some other function. Some of the nastiest bugs I’ve ever had to find were due to this.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 13, 2023, 10:04pm UTC](https://discourse.julialang.org/t/why-are-strings-immutable-historical-records-request/92115/6 "2023-01-13T22:04:27Z")

</div>

10 posts were split to a new topic: [Is Julia well-suited for string manipulation?](https://discourse.julialang.org/t/is-julia-well-suited-for-string-manipulation/92943)
