Composition and silent reads
May 10, 2011 Leave a comment
Copyright 2010-2011 © Gabriel Zs. K. Horvath
So far all the read operations performed in the atomic block were being recorded, so as to be re-executed at commit time. We will see in this post that there are circumstances where one does not want the reads to be recorded. I will call these silent reads.
Composition
One of the most important and powerful concept in software engineering is the one of composition. We want to be able to compose existing data structures together to build new ones. Or we want to add new methods to existing ones without having to perform open heart surgery on that component. So let’s look at the concrete example of trying to implement the Last method on top of the set data structure:
public IEnumerable<T> Last(this IEnumerable<T> that) { var enumerator = that.GetEnumerator() if (enumerator.MoveNext()) { T t = enumerator.Current; while (enumerator.MoveNext()) { t = enumerator.Current; } yield t; } }