C# 3.0 adds the "because" justification operator (!!).

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.

About these ads

28 thoughts on “C# 3.0 adds the "because" justification operator (!!).

  1. Mitch Denny

    Hi Omer,

    I think you miss the stunning miracle that is the because operator. The because operator will change the state of the universe so that the first expression is true. In fact – there is no need for he second expression – you can also do this:

    1 + 1 == 3!!

    This is often referred to as “just because” notation.

  2. Mitch Denny

    Hi Simone,

    Lets say your software requires a whole heap of storage on the file system, say more that your computer has available. Well then you can use the because operator to change the storage capacity at the quantum level.

    disk.StorageCapcity > 500000000 !!;

    Here I am using “just because” notation for brevity.

  3. Omer van Kloeten

    Oh, no, Mitch, I fully understand: It’s the miracle of modern language engineering that allows such miraculous operators as the because operator.
    I was just under the wrong impression that you can take shortcuts to achieve its full effect. :)

    Great post, btw :)

    I like Nick’s new C# operator proposal. However, to be fully qualified, it should be written as “¿ (1 + 1 == 2) ?” (sans quotes). ;)

  4. Pingback: Joe.Blog » C# takes another giant leap forward

  5. Pingback: Blog-a-Styx : C# 3.0 : Nouvel opérateur : "because"

  6. andypaxo

    Wow, what will those .NET guys come up with next? I would hope there are some security restrictions here, there could be one or two implications where unscrupulous programmers are concerned…
    Earth.Shape == “Flat”

    And of course, when “¿ … ?” is implemented as the “why?” operator – will “¿ … ?!” become the “why not?”…?

  7. Alex James

    Well all this !! and ?! reminds me a lot of chess notation
    the only thing is so far I don’t see !! as meaning a particular brilliant move… quite the contrary in fact… ?! or dubious is more like it!

    I suppose this will be useful when writing assertions in tests?

  8. Mitch Denny

    Alex – it would be useful for assertions, however because the truth of the second expression not only overrides the first, but changes the state of the universe to make the expression true, it isn’t going to be that great for unit tests (unless of course you are happy with them all passing no matter what).

  9. Mitch Denny Post author

    Hi Richard,

    I’m not sure. It could be dangerous. You are basically saying go to a state of anthing but 1 + 1 == 3, so while 1 + 1 == 2 would be a logical state, but you might just as easily end up with 1 + 1 = int.MaxValue, which would be very unstable.

  10. Matt Warren

    How do these rumors get started? Someone must have got their hands on an earlier prototype or one of the sample snippets; because double-bang was never meant to be the ‘because’ operator. That was just a comment on the side used to justify it. No one really wanted it, but Erik thought it should be there for completeness. Well, its all scrapped now so it doesn’t much matter. We decided not to ‘language-ize’ the multi-core stuff in the same way as the query stuff. The double-bang and its kin were really meant to tie into the new CLR parallel core instructions. There were constructs to split execution and join thread fragments back together. The double-bang was really fringe stuff, it enabled evaluation of greatest probability across multiple parallel threads. Kind of like how Sum & Average is to the query stuff; double bang allowed you to evaluate the same condition in seperate states at the same time, producing a ‘blended’ value across all the time slices. In this way, you could compute the ‘most common’ value in o(1) time. I didn’t get it either. Erik assured me this operator has used in the quantum computing domain. Of course, I laughed at that. Erik only grinned. Which made me wonder what he’s been up to lately.

  11. Mitch Denny Post author

    So Matt, what you are saying is that they did this:

    !! != because !!;

    And the world realigned itself destroying the language feature?

  12. Matthew Vines

    This is an older post, but I’ve been back and forth on how I felt about this new operator for a bit now. But I have a scenario that show some promise.

    (emp == cust !! (emp.fname == cust.fname && emp.lname == cust.lname && emp.ssn == cust.ssn))

    Now, if you had already overwritten the == operator to equate on some other criteria, this would be a great way to say, “Just in this case these two objects are equal if…”.

    I can see a lot of potential in this, but also a lot debugging nightmares from abuse.

  13. Nathan Black

    person.IsRight !! person.IsWife

    great… my world has just collapsed. I always accuse my wife of not being logical. Now thanks to C# 3.0, she is. AAAAHHHH!!!
    :)

  14. Pingback: Paul Stovell says… » Mitch Denny on C# 3.0

  15. Scott Barnes

    This is why i come to work each day here at Microsoft HQ. To make sure features like this continue to happen.

    Now onto looking at how to inject the DNA of a monkey into Silverlight’s runtime – why, because if the world ends tommorow two things will survive. Silverlight and Cockroaches, at least this way aliens can mutate the cockroaches with monkey dna..and we in turn can evolve again.

    True story.


    Scott Barnes
    Rich Platforms Product Manager
    Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s