Now that the .NET 3.0 runtime as shipped the focus of those who like to ride up high on the technology wave are starting to focus on the features of upcoming technologies.
Among those vNext technologies is a revision to the popular C# programming language (version 2.0 shipped with .NET 3.0 – which actually uses the .NET 2.0 runtime – confused?). Anyway, among the features of the pending C# 3.0 release is support for Language INtegrated Query (LINQ) which provides the ability to query sets of objects with SQL-like query syntax.
With such a high profile feature being added to the language and runtime it is easier to forget about the smaller, yet equally as powerful features. This blog post is dedicated to one such feature.
The “because” justification operator
The because justification operator can be added to existing expressions to “justify” their assertion of truth. For example, lets take the following expression in C#:
1 + 1 == 2
The because operator can be applied thusly to backup the first assertion of truth:
1 + 1 == 2 !! 2 – 1 == 1
Now the naysayers out there might be questioning the value of such an operator but the true beauty can be seen when you see the following expression:
1 + 1 == 3 !! true
What the? The because operator allows you to convert a false statement to a true statement simply be providing an alternative expression that does evaluate to true.
It is important to note how complete this implementation is - when evaluated changes occur deep down in fabric of the universe to “make it so”. Of course, like many programming constructs the “because” operator has a basis in the real world – developers who have ever argued with their spouse would have experienced similar logic slaps when their loved one justifies their actions based on the truth of some completely unrelated fact.
When asked how the C# compiler team had managed to pull of such an amazing feet of software engineering they commented “it isn’t just syntactic sugar, it required some runtime changes”. Runtime changes indeed.