In the many core world we now live in, programmers have begun to pay more attention to threading, immutability and functional style programming. For those of you keen to these trends, you may have heard of futures or promises. These constructs act as proxies for values that are yet to be calculated and are typically used to aid with synchronization issues in concurrent programming languages, such as C#.
Similar to futures, pasts, are a useful and almost unheard of construct that helps developers maintain previously calculated values. Pasts are not a C# language feature, but they are easy to develop on your own. The idea is simple:
- Calculate a value, v.
- Create a new Past object P holding the value v.
- Use the Past object P when you need the value v.
As you can see, this straightforward alternative to referencing variables directly can really be useful in programs which need to access the same variable value multiple times. Let's see what a Past object might look like.
We've essentially created a heap dwelling wrapper for some data, potentially primitive stack dwelling data. Yes I know what you're thinking, and the answer is a resounding Yes! Pasts can box primitive data better than that kludgey old object thing can! And you don't have to deal with inheritance chains and casting, yuck! Pasts are almost as easy to use as they are to develop:
The re-usability in the Past class above should sell itself! Embrace and use Pasts, they are a truly unique and
useless useful data structure. Stop back the same time next year for an eye opening post on Durings, you'll actually see the bits themselves change!