Consistency and Null Coalescing Operators

I’ve been trying to be more consistent lately with my blog entries, making at least one a day during the Monday through Friday work week.  Well, that has sort of kind of maybe not really worked out too hot yet.  But as I sat and thought, while reading through some blogs, I stumbled on Stuart Thompson’s blog where he mentions Null-Coalescing Operators.  These suckers are great!

Per the example on his site, what we used to type when checking for nulls appeared something like this:

1 namespace SomeNamespace

    2 {

    3     public class Coalescing

    4     {

    5         private string emailAddress = string.Empty;

    6         private string parsedValue = string.Empty;

    7

    8         public string CheckForParsedValue()

    9         {

   10             if (parsedValue != null)

   11             {

   12                 emailAddress = parsedValue;

   13             }

   14             else

   15             {

   16                 emailAddress = “(Not provided)”;

   17             }

   18

   19             return emailAddress;

   20         }

   21     }

   22 }

but now will be coded in a super awesome elite looking way of:

10 string emailAddress = parsedValue ?? “(Not provided)”;

I’m stoked personally, and I think this makes a great tip o’ the day!  Of course it is kind of a “future” tip o’ the day.  Thanks Stuart pointing out this interesting tidbit of future C# coolness.

Smile [:)]

Keeping Up in the Last Week of August

For that “keeping up” category entry this week I’ve hit up a few web site pages that have current topics of concern.

The first I dug up was “Creating a managed service factory” by Martin Hinshelwood. Martin does a great job of laying out an interesting idea for managing multiple services via a factory.  Read it, it is interesting (I’m still processing and groking what is going on here).

While reading through some of Martin’s material I stumbled into an entry on “hosted TFS pilot program” by Jim Lamb.  With the problems I have had with personally hosted TFS servers, and my return to Subversion and other solutions, I’d love to have access to a reasonably priced TFS hosted solution.  As a matter of fact, it would RULE!

On another topic, while checking out the latest Code Project e-mail I received I discovered another code generator I had not seen before.  It is called Smart Code and it is open source!  I dug a little into the article and discovered it is maintained by a company called Kontac.  The produce business rules management software and other tools.  Check out Kontac‘s website for Smart Code.

The last article I read through was a write up on the ole’ trusty Command Pattern titled “Behavioral Patterns:  Writing Command Pattern with C#” by Francesco Carata.

Most of these articles I found I received via one of the weekly e-mails sent out by Code Project.  Code Project is an awesome site with some great articles and great content contributors.

'ref' and 'out', Key Language Elements to Know :: Tip O' The Day

The ‘ref’ and ‘out’ keywords for parameters are rarely used, so I thought they’d make a great tip o’ the day.  Enjoy, and take it easy on the ‘ref’ and ‘out’ keywords.

The ‘out’ keyword on a parameter basically is like making that variable an additional return type value.  However, if the ‘out’ keyword is commonly used, you are probably in need of some code refactoring.

‘ref’ parameters on the other hand are passed into and out of a method, and are not required to be assigned prior to use in a method.  This is also one of the primary differences in the usage between ‘out’ and ‘ref’.

Check out the samples below that I nabbed from MSDN, they clarify well.  Smile [:)]

From MSDN Sample:

From the MSDN Sample code:

‘ref’ Example

1 using System;

    2

    3 namespace ConsoleInterface

    4 {

    5     internal class RefExample

    6     {

    7         private static object FindNext(object value, object[] data, ref int index)

    8         {

    9             // NOTE: index can be used here because it is a ref parameter

   10             while (index < data.Length)

   11             {

   12                 if (data[index].Equals(value))

   13                 {

   14                     return data[index];

   15                 }

   16                 index += 1;

   17             }

   18             return null;

   19         }

   20

   21         private static void Main()

   22         {

   23             object[] data = new object[] {1, 2, 3, 4, 2, 3, 4, 5, 3};

   24

   25             int index = 0;

   26             // NOTE: must assign to index before passing it as a ref parameter

   27             while (FindNext(3, data, ref index) != null)

   28             {

   29                 // NOTE: that FindNext may have modified the value of index

   30                 Console.WriteLine(“Found at index {0}”, index);

   31                 index += 1;

   32             }

   33

   34             Console.WriteLine(“Done Find”);

   35         }

   36     }

   37 }


‘out’ Example


1 using System;

    2

    3 namespace ConsoleInterface

    4 {

    5     internal class OutExample

    6     {

    7         // Splits a string containing a first and last name separated

    8         // by a space into two distinct strings, one containing the first name and one containing the last name

    9

   10         private static void SplitName(string fullName, out string firstName, out string lastName)

   11         {

   12             // NOTE: firstName and lastName have not been assigned to yet.  Their values cannot be used.

   13             int spaceIndex = fullName.IndexOf(‘ ‘);

   14             firstName = fullName.Substring(0, spaceIndex).Trim();

   15             lastName = fullName.Substring(spaceIndex).Trim();

   16         }

   17

   18         private static void Main()

   19         {

   20             string fullName = “Yuan Sha”;

   21             string firstName;

   22             string lastName;

   23

   24             // NOTE: firstName and lastName have not been assigned yet.  Their values may not be used.

   25             SplitName(fullName, out firstName, out lastName);

   26             // NOTE: firstName and lastName have been assigned, because the out parameter passing mode guarantees it.

   27

   28             Console.WriteLine(“First Name ‘{0}’. Last Name ‘{1}’”, firstName, lastName);

   29         }

   30     }

   31 }

Staying On Top of the Industry, The Keeping Up List

Focus Points:

There are two primary focus points for staying up to speed with software development.  Maintaining these key focus points is invaluable to one’s self for career promotion and personal meritocracy, career integrity, and keeping the stress levels low!

  • Language Features and Technology

Some of the key points to be aware of in the software development industry are language features and technology.  In C# the development paradigm follows that of object oriented development, with the standard inheritance, polymorphism, and other such features.  There are other languages, features, and language subsets that are working to extend these basic object oriented notions.  They range from Scala to F#.

Other things that are somewhat uncommon also should be sought and researched when possible to assure the full range of feature sets within a language are used well, including things like the often overlooked “out” and “ref” parameter passing modes, or the .  These are just some of the things that software developers should be aware of, if not intimately familiar with to some degree or another.

  • Frameworks, Libraries, Factories, Patterns, and Theory

Frameworks, Libraries, and “Factories” as Microsoft calls them sometimes converge into what is essentially the features of a language.  Often though they also extend far beyond, with frameworks for image manipulation, financial transactions, capitol markets, math intensive calculations, and other such industries.  These frameworks generally expose a particular API or service availability for development efforts.  The frameworks, libraries, and even somewhat misnamed “factories” that Microsoft release from its Patterns and Practices group could be argued to be even more important than the language feature themselves.  What can be done with frameworks is often extensive and often simplifies tasks in massive ways.  Regularly the effort is effected to such a degree that the level of familiarity with the underlying logic and business of a framework is almost completely removed.

Some of the other items that are coming up soon are things like LINQ, and F#, which absolutely change the development paradigm that we developers have been working in.  In a mere number of months when Visual Studio 2008 is released with the framework 3.5 the development world will make what should be another massive shift in improved productivity.  Some developers even touting a 2-3x multiplier in work completion.

Places to Think, a.k.a "My Third Place"

I got up after a development all-nighter a few days ago.  The GF and I hit the computers at about 10:00pm.  We both played WOW for a bit.  She kept up the adventures of WOW while I jumped into dev mode about 11:15pm.  From 11:15pm until 5:00am I coded away with .netTiers, Windows Apps, and trying out different scenarios with the various entities and database generations.

When I got up that morning and I was still in that mind set.  I got myself together just barely and headed out the door to my thinking place.  So what is that place?  I like to work, think, and ride the streetcar all at once.  For some reason it helps me keep my thoughts together and focused even when there are dozens of people getting on and off, conversations taking place, and all sorts of hustle and bustle.  I like being able to look out the huge glass windows and contemplate and see changing scenery.  Other places I prefer are coffee shops and various other places I’ll leave unmentioned at the moment.

I ponder sometimes, what are the places other people like to work aside from just the office.  Then of course, does anyone really like being in the office, some do, but I gather that many don’t?  I have mixed feeling about being in the office.  When offices are distractive, I generally like to grab a streetcar ride somewhere and get away from the disruptions, but if the office is calm and it is easy to work I don’t mind being where the other minds are working away on similar solutions.

I ponder what other’s places to think are?