Improve XAML Load Time in Visual Studio 2008

I’ve noticed that whenever I attempt to open up a XAML file in VS 2008 it will freeze up for about 5 seconds. Then whenever I make any changes to the XAML visual studio will freeze up again for about 5 seconds.

To be fair I have a pretty significantly sized XAML application and it seems the real slow down comes from including a Merged Resource Dictionary with a large amount of templates. But freezing up visual studio for this amount of time is incredibly painful.

I have managed to finally get rid of this delay by changing the options for XAML files to “Always open documents in full XAML view”.

You can find these options in Visual Studio 2008 by going to Tools->Options->Text Editor->XAML->Miscellaneous. Thank the flying spaghetti monster for this option!

Prisoner’s Dilemma .NET

The prisoner’s dilemma is a classic game of logic that has made its way into the computer science arena in the past. I am presenting Prisoners Dilemma.NET as a general programming challenge based around this game. I will be accepting custom built prisoners and facing them off in a master interrogation competition at the end of this challenge.

The challenge deadline will be May 1st, 2008. All you have to do is to create your prisoners into 1 or more .NET assemblies (v2.0 or greater) and send them to me in a zip file to enter the challenge.
I have created a prisoners dilemma application for you to use as a test bench for prisoner creation. It comes complete with the prisoner’s dilemma core source code for you to review, unit tests and a WPF application to see how your prisoners line up against other prisoners visually. There is a sample project created for you called “CustomPrisoners” with a basic prisoner outlined. All you need to do is implement a few abstract methods to get your prisoner going.
For example, here is the Mafia Hitman source code:
public class MafiaHitman : Prisoner
{
    public override bool Interrogate(string partnerId)
    {
        return false;
    }
 
    public override void Sentence(InterrogationResponse partnerResponse, string partnerId)
    {
    }
 
    public override string Name
    {
        get
        {
            return “Mafia Hitman”;
        }
    }
}
 
Why the Prisoner’s Dilemma?
For a real detailed explanation of the prisoner’s dilemma you should head over to the Wikipedia article for the Prisoner’s Dilemma. If this is too dense for you and you would prefer someone to explain it in simpler terms I recommend hearing Richard Dawkins explanation, from Nice Guys Finish First. It’s lengthy but quite good.
What caused me to put together this challenge, though, was a conversation I had with a colleague regarding the use of torture as a valid means of interrogation. At some point in the discussion I decided to use the Prisoner’s Dilemma as an example to counter one of his arguments. Essentially he was arguing that American’s should be allowed to torture terrorists because they are also torturing American soldiers. So, of course, this discussion gets much more complicated than this but when I brought up the idea that the Prisoner’s Dilemma should illustrate that cooperation is more beneficial than betrayal (or not torturing enemies of America as, at least, a gesture to also not torture American soldiers) he disregarded the study and claimed that it has questionable scientific validity to begin with.
So as someone who values reason I would like to perform a bit of a scientific study to validate or invalidate the theory behind the Prisoner’s Dilemma before we continue with this point of the debate.
Challenge Details
·         You may freely download and run the source code for the Prisoners Dilemma .NET challenge. You may also modify it but this is the code that will run for the challenge.
·         Changes may be made to the PrisonersChallenge.Core code base between now and the challenge deadline. Be sure to check more recent blog posts for notifications of any changes before submitting your entry. Anybody who has already made an entry will be notified of changes if contact information is available.
·         Changes will not be made to the codebase unless major bugs are found or critical security issues are revealed with the present codebase.
·         You must submit only a single .NET library file (dll) per submission. All other file types will be disregarded.
·         All entries must be packaged in a single zip file. So that means 1 dll in 1 zip file is an entry.
·         (optional) You should create an Assembly level attribute in each submitted assembly of the type PrisonersDilemma.Core.PrisonerAuthorAttribute with your name and email address so I can get back to you later with results.
·         The challenge will be run on a VPC with limited memory and no internet access.
·         No code obfuscation allowed.
·         No private reflection allowed.
·         The challenge will be run in a medium trust environment.
·         You may use the Temporary folder for writing files if you so choose.
·         You may package files and 3rd party assemblies as embedded resources in your prisoner assembly if you so choose but your submission must be only a single .NET assembly file.
·         By submitting code to this challenge you give me (Justin Chase) the rights to execute and distribute this source code as I see fit.
·         I reserve the right to deny any entry for any reason.
·         Entries will be denied if they appear to be doing anything malicious to the machine or to the memory of the application.
Challenge Procedure
Each prisoner will iteratively be interrogated against each other Prisoner. What this means is that for each prisoner in the application your prisoner will be put up against that prisoner 100 times. A unique value will identify each prisoner so they can keep track of each interrogation against a specific partner.
Insanity Variation
Given the fact that I’m executing arbitrary, 3rd party code for this challenge I, naturally, needed to cover the situations where a Prisoner throws an exception from within its Interrogate or Sentence methods. Rather than take down the entire application for these scenarios I have decided to eat those exceptions and treat them as if the Prisoner has “plead insanity”. If a prisoner does this then they will receive the maximum sentence.
This has some interesting implications because it expands the previous game states from 2 possible choices to 3, which adds a little variety into the mix. I will draw up a small chart to illustrate the various possibilities.
A / B
Silent
Betray
Plead Insanity
Silent
2, 2
5, 0
2, 5
Betray
0, 5
4, 4
4, 5
Plead Insanity
5, 2
5, 4
5, 5
 
I chose these values by the following logic:
·         This whole theory assumes that both parties are in fact guilty and that the reward comes from not being able to be proven guilty with 100% certainty.
·         If you’ve plead insane then you are known to be 100% guilty.
·         Betraying someone who has pleaded insanity does not benefit the cops at all, you are simply admitting your own guilt.
·         This probably won’t change the game too much since it’s unlikely anyone will ever take the tactic of intentionally pleading insanity.
Recommendations
It’s well known that the “tit for tat” strategy was the winning strategy behind the original Prisoner’s Dilemma challenges. I would love to see some interesting tit-for-tat prisoners appear on the scene but it will only be interesting if we have lots of varied strategies to compare it with. I have included a few basic strategies that aren’t very interesting but I would love to see every possible tactic exhausted for comparison.
Just remember this isn’t a competition! This is a programming challenge intended to be fun and to be a casual scientific experiment so please, create a variety of interesting prisoners.
If you find any bugs in the source code or have any recommendations feel free to email me directly!

Double Divide By Zero is NaN

I learned something simple today. It seems like I should have known this already but I just realized that doing a divide by 0 against a double will not result in a DivideByZeroException. This may be good or bad depending on your application but if you’re not aware of it it can result in some strange behavior.

Actually the result is only NaN if you divide 0.0 / 0.0. If you divide 1.0 / 0.0 you result in infinity.