Book Review: Head First Statistics

I find writing reviews of the Head First series of books difficult. Not because they are badly written, or because they do not cover the subject matter well. It is simply that they are so good. So let me set the tone by saying: I challenge anyone to find a better book for learning basic probability and statistics!
Head First Statistics was written by a mathematician for non-mathematicians. The author and editors have obviously put in a great deal of effort to create something out of the ordinary. This book is clearly a labour of love, as it is a low effort and fun way to learn probability and statistics!
I studied Mathematics at university, and statistics was something I had little contact with until a first year introduction to the subject. This clear and simple book will take you painlessly from having absolutely no knowledge of probability and statistics, to a level commensurate with university entrance. It stops short of deriving the central limit theorem from first principles, but it will make you aware of what it is and show you how it can be applied. I gained a clear understanding of concepts I had merely glossed over at university over 20 years ago.
This is an interesting and engaging book, written in the Head First series’ hallmark style (tells you how, but also shows you why). Even if you have absolutely no knowledge of statistics, it will not be a barrier to gaining an in-depth understanding of basic statistics from this book. I really enjoyed reading this book. Highly Recommended.
I did find a few spelling mistakes, and another reviewer on Amazon pointed out that there were a few mistakes in the exercises (I must confess I didn’t work through every single one!).
Disclosure: a copy of this book was supplied by O’Reilly. I did not let that influence this review.

CodeRush Xpress for Visual Studio: Free

I’m a big fan of ReSharper (despite the fact that I still haven’t mastered all of the commands and shortcuts) and the features it brings to code editing in Visual Studio 2005 and 2008. When you see people like Jean Paul Boodhoo using it to the full, it’s sheer wizardary! So I hope the people at JetBrains won’t brand me a traitor(!) when I mention that CodeRush Xpress for Visual Studio 2008 is now freely available.

But, be careful if you have CodeRush or ReFactor! already installed:

  • Does not support Visual Studio Express Editions.
  • Cannot be installed side-by-side with other CodeRush or Refactor! editions.

Reminder: Perth .NET User Group Meeting Tues 4th Nov, 5:30pm: F# with Nick Hodge

TOPIC: F# > functional with Nick Hodge
DATE: Tuesday, November 4th, 5:30pm
VENUE: Excom, Ground Floor, 23 Barrack Street, Perth
COST: Free. All welcome

Join us at the Perth .NET Community of Practice, Tuesday November 4th to hear Nick Hodge present a session on F# and the rise and rise of the new .NET functional and dynamic languages, where and when to use them, and why F# is NOT the new C#!

String.Split(): Skip Empty Entries

At the risk of publicising that I’m the last person to know this(!), I recently discovered that String.Split() has an overload that takes a parameter
StringSplitOptions.RemoveEmptyEntries that does exactly what it says, like this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #a31515; }.cb3 { color: #2b91af; }

char[] separator = new char[] { ',' };
string[] result;
string toSplit = "Rick,Dave,,Nick,,,Roger,";
 
result = toSplit.Split(separator,
                       StringSplitOptions.RemoveEmptyEntries);
foreach (string s in result)
{
    Console.WriteLine("[{0}]", s);
}

This is also very useful for splitting text where extra whitespace should be ignored:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #a31515; }.cb3 { color: #2b91af; }

string woods = "The woods are  lovely, dark and deep.." +
               "But I  have promises to keep, " +
               "And miles to  go before  I sleep,, " +
               "And   miles to go before I sleep.";
char[] whitespace = { ' ', ',', ';', ':', '.', '!', '?' };
 
string[] words = woods.Split(whitespace,
                             StringSplitOptions.RemoveEmptyEntries);
foreach (string s in words)
{
    Console.WriteLine("[{0}]", s);
}

Perth .NET User Group Meeting, Tues Nov 4th, 5:30pm: F# |> Functional with Nick Hodge

Join us at the Perth .NET Community of Practice, Tuesday November 4th to hear Nick Hodge present a session on F# and the rise and rise of the new .NET functional and dynamic languages, where and when to use them, and why F# is NOT the new C#!

TOPIC: F# > Functional with Nick Hodge
DATE: Tuesday, November 4th, 5:30pm
VENUE: Excom, Level 2, 23 Barrack Street, Perth
COST: Free. All welcome

Nick is a self-confessed professional geek working for Microsoft. He has over 22 years of IT industry experience in a variety of sales, technical, management, semi-marketing and strategic roles. He is a sought-after presenter, prolific social networker and closet workaholic.

Please Note: This meeting is not in our usual Thursday slot.

C# Tips and Tricks

There is a very useful post over at StackOverflow on some of the less known parts of C#. Here are a few of my favourites:

Default Event Handler:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #2b91af; }.cb3 { color: green; }

public delegate void MyClickHandler(object sender, string myValue);
public event MyClickHandler Click = delegate { }; // add empty delegate!

Let’s you do this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #a31515; }

public void DoSomething()
{
    Click(this, "foo");
}

Instead of checking for null before invocation:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: green; }.cb3 { color: #a31515; }

public void DoSomething()
{
    if (Click != null) // Unnecessary
    {
        Click(this, "foo");
    }
}

Chaining the ?? operator:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #2b91af; }

string result = val1 ?? val2 ?? val3 ?? String.Empty;

And it never ceases to amaze me that many devs don’t use System.IO.Path.Combine(), instead of:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: #a31515; }

string path = dir + "\\" + fileName;

Do You Review?

I can honestly say I love where I work. And today was a classic example why. I had a code review! (does your team have code reviews?). One of my colleagues pointed out I could make use of Nullable GetValueOrDefault() in the following code snippet:

Instead of this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: blue; }.cb2 { color: green; }.cb3 { color: #2b91af; }

int? objectID;          // passed in to a method...
DateTime? signedDate;   // --- "" ---
 
if (objectID == null)
{
    objectID = 0;
}
 
if (signedDate == null)
{
    signedDate = (DateTime)SqlDateTime.MinValue;
}
 
SomeDBWrapperMethod((int)objectID, (DateTime)signedDate);

Just do this:
.cf { font-family: Consolas, Courier New, Courier, Monospace; font-size: 9pt; color: black; background: white; }.cl { margin: 0px; }.cb1 { color: #2b91af; }

SomeDBWrapperMethod(objectID.GetValueOrDefault(), 
                    signedDate.GetValueOrDefault((DateTime)SqlDateTime.MinValue));

Seems so obvious, after the fact! I’m sure I must have come across this before, but I can’t remember having ever used it. It’s great to have extra pairs of eyes go over your code.