The Untouchables (part III) – Adding iterators to our immutable stack

Introduction In my last post I showed you a VB translation of Eric Lippert’s immutable stack class. There was however one thing that was lost in translation. In Eric’s original code he made the class enumerable (added support for a For Each loop). Because C# has support for iterators with its yield keyword, that was very easy to do… in C#. VB currently doesn’t have this feature so to add the same support we need to implement both the IEnumerable(Of T) and the IEnumerator(Of T), which in turn requires the implementation of the non-generic IEnumarable and IEnumerator and also the … Continue reading The Untouchables (part III) – Adding iterators to our immutable stack

The Untouchables (part II) – Creating an Immutable stack with VB

Introduction In this article I will shamelessly “steal” the great work originally posted by Eric Lippert on his blog. However I will translate his code into VB and try to explain it from a VB developers point of view. In my last post, I described what immutable objects are and what the advantage of using them would be. It also described how you could create an immutable class and use it as if it was value type. This time we are going to take this a step further and create an immutable stack. An immutable stack, is that possible? As … Continue reading The Untouchables (part II) – Creating an Immutable stack with VB

The Untouchables – Creating Immutable objects with VB

There are many articles available on the Internet about immutable objects in .Net. Unfortunately almost all of them are addressed toward C# developers. In this article I’m going to rectify that by providing some information on the subject aimed toward the VB developer. Immutable objects are a very simple yet powerful concept within programming. An object is immutable if its state cannot change after it has been created, which means that all its members need to be read-only. The integer number 1, for example, is an immutable number. There is nothing you can do that changes it. You can’t make … Continue reading The Untouchables – Creating Immutable objects with VB

Make immutable objects mutable

In .Net the String object is an immutable object, which means that it’s basically constant and can’t be changed. You can’t change a string, you can only create new strings. The various methods that the String class have never directly change the string they operate on, instead they return a new string. Dim myString As String = "Hello World" Dim mySecondString As String = myString.Substring(0, 5) Console.WriteLine(myString) ‘Hello World Console.WriteLine(mySecondString) ‘Hello Even though we developers modify strings all the time, which can make them look mutable, they aren’t. What happens is that a new string is created and the reference … Continue reading Make immutable objects mutable