While C# has the "because" operator, VB.NET has the "why" query operator

Although VB.NET has in the past missed out on some fairly crucial language features such as anonymous methods and iterators (both absent from VB2005 which shipped with .NET FX 2.0) it seems that it is going to edge C# out in the race for the most obscure operators.  Mitch posted about the C# implementation of the "because" or "justification" operator.  The VB.net equivalent will looks something like:

1 + 1 = 2 because 2 - 1 = 1

1 + 1 = 3 because true

1 + 1 = 3 justbecause

Although the implementation is a little more wordy (literally) they extended this concept by adding the "why" operator.  For example

why 1 + 1 = 2

The real question would be what does the why operator return and where could you use it.  Well in the simplest terms the why operator allows the framework to expose any previously defined truths.  For example in Mitch's case where he defined the truth 1 + 1 = 3, you could write the query why 3 + 3 = 9 which would return a proof which includes the truths (1 + 1 = 3, 1 x 3 = 3) as well as an execution plan in the form of a proof tree indicating the order that these truths are applied.

You would think this would be something that C# could easily add into their syntax, allowing you to write:

¿ (1 + 1 == 2)

But unfortunately I have it on good authority that C# will not get this feature as they deem it to be too productive and is a security hole as it allows the developer to query the logic of the .NET Framework developers at Microsoft.

Published Sunday, November 26, 2006 8:37 PM by nick
Filed under: , ,

Comments

Sunday, November 26, 2006 8:39 PM by Mitch Denny

# re: While C# has the "because" operator, VB.NET has the "why" query operator

Wow! Out smarted by the VB guys again :)
Sunday, November 26, 2006 9:05 PM by vikram

# re: While C# has the "because" operator, VB.NET has the "why" query operator

hi

I have not been able to understand what can be  a real world use for this. It does not seems to have any use in web programming at least
Monday, November 27, 2006 3:11 PM by Darren Neimke

# re: While C# has the "because" operator, VB.NET has the "why" query operator

Nick, is it also true that the WhyOhWhyException will make an appearance in the next revision of hte .NET Framework so that we can correctly handle exceptions arising from these silly operators? :-)
Monday, November 27, 2006 4:37 PM by nick

# re: While C# has the "because" operator, VB.NET has the "why" query operator

Yes.  From what I understand they were originally going to implement the JustBecause operator overload as an exception which would be raised if you try to question something that wasn't based on a set of truths.  I like the WhyOhWhyException because unlike a number of the other framework exceptions where you get a FXCop warning saying that you shouldn't use them, this exception was designed so that developers could use it.  
Tuesday, November 28, 2006 11:24 PM by Alex James

# re: While C# has the "because" operator, VB.NET has the "why" query operator

Nick, you and Mitch are so wicked...