Fabulous Adventures In Coding

Eric Lippert's Blog

Immutability in C# Part Five: LOLZ!

My sadly soon-to-be-erstwhile coworker Cyrus made me a lolgeek shirt to go with this series of blog articles:

ShirtFront ShirtBack

Cyrus, needless to say, is a big goof. Thanks, dude!

Published Thursday, December 13, 2007 11:19 AM by Eric Lippert
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Luke said:

Is it wrong that I love this sort of thing?  Alas, I'm a nerd, through and through.

December 14, 2007 11:50 AM
 

Tanveer Badar said:

But I must say that i++ spoils all the fun. We are talking about immutable data structures and it mutates 'i'.

December 14, 2007 2:18 PM
 

Eric Lippert said:

Yeah, stupid i++ !

December 14, 2007 2:55 PM
 

silky said:

Well, the object held in "i" isn't mutated (probably, we can't be sure because maybe "i" isn't an int and there is some funky operator overloading going on) the variable "i" is just set to something else.

December 14, 2007 9:52 PM
 

Tanveer Badar said:

Trust your instinct. I am not a compiler who is paranoid of even ++ and the language ain't C# either where overloading + automatcially gives you cousins for free. I must assume that ++ mutates the object it is invoked on.

December 15, 2007 8:54 AM
 

Eric Lippert said:

I am not following the train of thought of either of you.

If i contains an int then the int is not mutated; ints are immutable.

The operand of the ++ operator is always a variable. No matter what the type of the variable is, and no matter what is presently stored in that variable, a successful ++ operation always mutates _the variable_.  Whether the contents of the variable are mutable or immutable is irrelevant; the variable is going to change.

(Well, someone could write a ++ operator which set the variable to its current value, not mutating it, but we could characterize the trivial mutation as a mutation for the sake of argument.)

Hence the shirt -- i'm mutating your variables.

December 15, 2007 10:32 AM
 

Mike said:

alright... that was deep;

i now fully appreciate that shirt... as obvious to before you explained it... i didn't get it :]

lol.... I must of re-read your explaination at least 4 times before getting it though;

-mike

December 17, 2007 3:50 PM
 

Sasan Jalali said:

O.K. The shirt is fun but a variable is not in the realm of Data Structures!

In this context 'i++' can only mean a better 'i'mmutable Data  Structure! ( as C++ means a better C )

So keep up the good work,

Sasan

December 18, 2007 5:23 PM
 

Tales from the Evil Empire said:

For some reason, there's been a lot of buzz lately around immutability in C#. If you're interested in

January 18, 2008 4:04 PM
 

Richard said:

The mark of a true geek. See a joke about a computer science concept and then dissect it to see if it's really funny.

April 29, 2008 9:31 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit

About Eric Lippert

Eric Lippert is a senior developer on the Microsoft C# compiler team. Before that he worked on the framework of Visual Studio Tools For Office. Before that, he worked on the compilers, runtimes and tools for VBScript, JScript, Windows Script Host and other Microsoft Scripting technologies. He lives in Seattle and spends his free time editing books about programming languages, playing the piano, and trying to keep his tiny sailboat upright in Puget Sound.

This Blog

Syndication


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker