I am a developer at Microsoft and work in the .NET Common Language Runtime (CLR) team. For the last 4 years I have been working on virtual machine technologies on a variety of form factors including desktops (Windows, Linux), tablets (Win8), gaming-consoles (Xbox 360), mobile devices (Windows Phone 7, Windows CE, Symbian).I have worked on various core pieces of the runtime including Garbage Collector, memory manager, platform abstraction layer, runtime-performance, etc.Before working on .NET I worked on Visual Studio Team Foundation Server, Visual Studio Team System, Adobe Framemaker, Adobe Acrobat, Texas Instrument's Code Composer Studio.
Last year I had posted about a a drum playing machine I had seen.
This time I got a full video of it in action. Looks and sounds awesome
Mutable objects can lead to situation wherein it can be put into a hash but never retrieved from it (or rather even worse something else gets returned)...
Even though it is evident in most cases, but its not so evident all the time especially when we have deep hashcode dependencies. Consider the following
class Person { public Person(string name, Person parent) { this.name = name; this.parent = parent; } public string name; public Person parent; public override int GetHashCode() { int hashCode = name.GetHashCode(); if (parent != null) hashCode ^= parent.GetHashCode(); return hashCode; } } static void Main(string[] args) { Dictionary hash = new Dictionary(); Person parent = new Person("Beeblebox", null); Person zaphod = new Person("Zaphod", parent); hash.Add(zaphod, zaphod); parent.name = "SomethingElse"; Console.WriteLine(hash.ContainsKey(zaphod)); // Will print false }
Here Person is mutable on different levels. Its directly mutable and also deep-mutable as it contains a reference to parent (which in turn is mutable).
Additionally, Person's hashcode depends on it's mutable fields. So in effect if any of the mutable references change then the next GetHashCode will return a different value and hence its lookup inside Dictionary will fail as Dictionary uses the hashcode of the objects place inside it.
Since in the example above the mutation of parent happens inline, it's easy to figure it out. However, it could well be in some obscure corner of the code base.
Today is world teacher's day, a day dedicated to some of the most important people in our lives. For me this is even more important because I come from a family of teachers including my father, grand mom and a lot of my uncles/aunts and even my wife.
I wanted to take this opportunity to thank all my teachers who have helped me reach where I'm today.