Archive for October, 2008

Avoiding my Vanguard account like the plague

October 23rd, 2008
I have been avoiding logging into my Vanguard account for the last month.  I don't want to see what has happened to my investments.  So when this (below) aired on SNL, I had a good laugh:

More Electoral Data

October 21st, 2008
After I blogged yesteday about Electoral-Vote.com, I stumbled across another great site for watching the electoral vote, RealClearPolitics.  Its basically the same data, but the totals are a little more conservative (not politically, but in the true sense of the word).  RealClearPolitics only totals those states that are polling 5%+ for a candidate.  As of October 21st, Obama is showing 286, McCain 160.

Data and the Presidential Election

October 20th, 2008
Political views aside, this has been a very interesting Presidential campaign season.  As we approach election day 2008, our friend the Electoral College becomes the focus of the news.  While early in the campaign new outlets such as CNN and USA Today focus on their nationwide polling, the election is actually determined by the electoral college which has become the recent focus. For the past few weeks I have been watching the polling at electoral-vote.com.  This site seems to do the best job of presenting polling data in an open, honest, and accurate way.  The web site places each state into one of 7 categories based on all available polling data for the last week.  The categories including Strongly Democrat (10%+), Weakly Democrat (5%+), Barely Democrat (1%+), Tied, Barely Republican (1%+), Weakly Republican (5%+) and Strongly Republican (10%+).  The site does a pretty good job of discussing polling, and how much of a lead a candidate should have in a poll to safely guess the vote.  Electoral votes are tallied based on the polling and displayed as a total, and placed into the above mentioned categories. If the election were today, Barack Obama has 264 votes from states that are Strongly Democrat, and John McCain has 137 from states that are Strongly Republican.  These votes are pretty safe.  What these data really drive home is that Obama only needs 6 votes to reach the 270 votes needed to win the election. Of course the news media outlets want you to keep watching their programming and reading their newspapers, so they concentrate on states that are close, or are "swing states",  to make the election seem close.  This is contrary to the data that show that Obama will almost certainly win if he can maintain his 10%+ lead in the 20 states plus District of Columbia that are categorized Strongly Democrat.  And no one can predict the future.  In the 14+ days until the election, perhaps we will learn that Obama did something horrific in his past and the vote will swing to McCain. No matter what your politics are, the data are very clear.

Catch Clause or: Crap! There is something I don’t know about C#.

October 18th, 2008
I first started programming .Net in 2000.  I got my hands on the Beta 2 version of .Net 1.0.  In those days I was programming in VB6, so VB.Net seemed like the best choice.  But a couple of weeks after downloading the beta I was in a book store and saw a C# book.  I picked it up and started thumbing through it.  I remember I said something out loud like, "Wow, this is just like Java!" I had programmed in Java for a while as well, and had a background in C/C++. I preferred the syntax greatly to that of VB.  From there on out I tried to do all my .Net stuff in C#. I recount this tale because I so rarely find something in C# I don't know or understand. This is bragging. Its just the reality of getting to know a language/environment over several years.  Of course there are new language features released every year or two that I have to work to learn.  But all in all, the language isn't much of a mystery to me.  So yesterday when a coworker told me I was using a throw statement in a catch clause wrong, I was very surprised.  I was doing something like:
try
{
  ...
  SomethingThatMyThrowEx();
}
catch(Exception ex)
{
  ...
  throw ex;
}
So what is wrong with this? I didn't see anything wrong at all. I wanted to catch the exception, take some action, and simply re-throw the exception. And this code will do that. The problem is, the exception will have a new stack trace from the point at which I re-throw it. Why? Because the throw statement takes and expression, not an object. The "ex" object in this case is being used as an expression of how the exception should look when thrown. This seems really strange, but it is in the C# language spec. Crap, how did I miss this all these years! When C#/.Net executes the throw line it uses the exception object as an expression of how the expression should be thrown, and ads a stack trace from the current location in code. The previous stack trace is gone. So how do we preserve the stack trace? We use only the throw keyword with no expression. This instructs .Net to simply continue the exception bubble-up process:

try
{
  ...
  SomethingThatMyThrowEx();
}
catch(Exception ex)
{
  ...
  throw; //no ex
}

Pretty simple, and pretty damn subtle. I won't forget that one!