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.

SQL Server scripts

A few SQL Server script resources:

Updated: added a few more.

MVP Award

This morning I received an email welcoming me into the Microsoft MVP award program. I would sincerely like to thank everyone for their support and encouragement. Over the last 5 years I have met and corresponded with several MVPs and have always had the highest respect for their skills, knowledge and commitment. It’s an honour and I hope I can live up to it.

Congratulations to Joe Albahari, who was also awarded MVP status today.

Perth .NET User Group Meeting: Thurs Oct 2nd, 5:30pm – 7pm: PLINQ and TPL: Hot New Solutions for Parallel Programming with Joe Albahari

Join us at the Perth .NET Community of Practice, October 2nd to hear Joe Albahari present a session on two parallel programming technologies at the forefront of threading in the .NET world. In this session, Joe will demonstrate both technologies, and look at how well they solve some real-world problems. He will also discuss what it means to think of LINQ queries as functional programming islands, and why this is important in how you code today. Finally, we’ll look at their relative performance, and whether PLINQ is indeed a practical solution for completely transcending the hard problem of thread safety.

TOPIC: PLINQ and TPL: Solutions for Parallel Programming with Joe Albahari
DATE: Thursday, October 2nd, 5:30pm
VENUE: Excom, Level 2, 23 Barrack Street, Perth
COST: Free. All welcome

More details here.