Thursday, March 13, 2008 1:53 PM
Immutable Data Structures in OO Languages.
One of the big reasons for the recent push towards functional programming languages is concurrent programming. Everyone is worried about how the switch from more megahertz to more cores is going to impact how they program.
I was reading an article entitled F# Primer over on msdn today. It stated that the reason F#, and other functional programming languages, are so much better when it comes to concurrency is that they encourage the use of immutable data structures. However, what is keeping us from using the same idea in our existing C# or C++ code? With an immutable producer-consumer model couldn't you achieve the same effect? Don't get me wrong, I think F# is a great language with concise and elegant syntax. But I don't see why you couldn't achieve similar results with C#'s readonly keyword or by using objects that only allow the setting of values in the constructor while having read only properties.