On the Lambda

Programming, Technology, and Systems Administration

On the Lambda

The Immutable String

August 4th, 2011 · No Comments · Uncategorized

One theme I see often on StackOverflow is that someone will post a question related to strings, and someone or several someones else will come along and say, “You can’t; strings are immutable.”

This is all well and good and accurate, but I have a problem with it.  You see, I think most of the people who ask these questions have never or only rarely encountered the word “immutable” in the first place.  They will generally have a weak or vague idea what it really means.  I blame Eric Lippert.

Let’s get this out of the way: the root word of “immutable” is “mutate”.  Something that is immutable does not have the ability to mutate. It never changes.

Applied to strings, this means that a string instance, once created, cannot be modified.  If you want to change a string variable, you have to create a brand new string instance and assign the new instance back to your variable.

It’s good there are more programmers out there that know these $5 words, but it’s even better if there are more programmer out there that can communicate the ideas behind the words to others who don’t yet know them.


No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment