Welcome

You have reached the blog of Keith Elder. Thank you for visiting! Feel free to click the twitter icon to the right and follow me on twitter.

Deep Fried Bytes 15: Visual Studio Tips and Running an Agile Team with Sara Ford

Posted by Keith Elder | Posted in Podcast | Posted on 20-10-2008

 Listen To This Episode

http://deepfriedbytes.com/podcast/episode-15-visual-studio-tips-and-running-an-agile-team-with-sara-ford/

 

Sara is a nut.  How nutty?  Well, would you write a book and give all the proceeds away from it?  No?  Well Sara is.  You’ll get the scoop in this episode.

We also discuss a lot about Agile methodologies.  Sara is the Program Manager for Codeplex.Com.  She has a unique perspective on Agile in that she has typically been involved on teams using traditional software methodologies at Microsoft.  That all changed when she joined the Codeplex team.  We discuss her journey moving from a traditional methodology to an Agile methodology. 

Ways To Listen To The Show

There are several ways to listen to Deep Fried Bytes.

1. Directly From The Web Site (or click the link above)

When you visit the site look for this:

Clicking the triangle will launch the Yahoo! media player and automatically start playing the show for you. As long as you leave the browser window open the player will stay open. Clicking off the page WILL stop the player!

2. Subscribe via iTunes and Zune

If you have iTunes or Zune installed on your computer you can subscribe to our show. In iTunes open the Music Store and search for “Deep Fried Bytes”. In the Zune software, go to the MarketPlace select Podcast and search for “Deep Fried Bytes” to subscribe to the show. You can also click either of the two icons below to automatically subscribe to the show if you have iTunes or Zune installed.

Subscribe via iTunes Store Subcribe via Zune Market Place

3. Subscribe to RSS Feed

To stay current and up to date with the show, subscribe to the site’s RSS Feed. If you don’t know about RSS feeds you can read more here: http://en.wikipedia.org/wiki/RSS_(file_format)

If you already have an RSS reader installed and setup, click the feed icon below to grab our news feed.

Subscribe to our podcast!

WCF vs ASMX WebServices

Posted by | Posted in .Net, WCF | Posted on 17-10-2008

This question comes up a lot in conversations I have with developers. 

“Why would I want to switch to ASMX services?”

One analogy I have come up with to explain the difference between the two is an airplane analogy. 

I associate ASMX services with a Cessna 150 cockpit and I associate WCF services with a 747 Jumbo Jet cockpit. 

image

I’ll be honest, I’ve never flown a plane but I think I’m smart enough to crank a Cessna 150 if I had to figure it out.  The above screen shot is a real Cessna 150 cockpit.  There are a few gauges, some knobs, etc.  Really not that bad.  And I think this explains ASMX really well.  ASMX services are easy to crank and jump start.  Think about it.  We take an existing Asp.Net website and add a file called “asmx”.  Any method we attribute with [WebMethod] magically turns into a service.  Objects we pass in and pass out that have public getters and setters will be serialized into XML.

   1: [WebMethod]
   2: public string FlyToDestination(Location loc)
   3: {
   4:     // up up and away
   5: }

The barrier to cranking and getting going with an ASMX service is really simple.  And because it is simple, we’ve adopted them on a massive scale.  Let’s turn our attention to WCF.

image

WCF is a jack of all trades.  Think of it like a large plane that can repurposed for hauling passengers, hauling cargo, military use or whatever.  We are dealing with a plane but it is all about how that plane is configured.  Because things can be configured a lot of ways with the WCF 747 plane there are a lot more buttons in the airplane cockpit as compared to the Cessna 150.  The flip side of this is that once you understand how to configure WCF you’ve got one of the most versatile plane in the world!

From a developers stand point, the same logic or code written in an ASMX service works in WCF.  The code between the curly braces is the same.  The bottom line in either case is a method gets called and an object gets passed in (we call this a message when talking about services).  The difference in WCF is we program to a specific contract.  Here’s the same example above done in WCF.

   1: [ServiceContract]
   2: public interface IAirportService
   3: {
   4:     [OperationContract]
   5:     string FlyToDestination(Location loc);
   6: }
   7:  
   8: public class AirportService : IAirportService
   9: {
  10:     
  11:     public string FlyToDestination(Location loc)
  12:     {
  13:         // up up and away
  14:     }
  15: }

Instead of attributing the specific method like we do in ASMX, in WCF we attribute the Interface.  Programming to an Interface is a good thing and the reason this is done is to loosely couple the host of the service from the implementation.  Doing this opens the door for hosting WCF services not only in IIS but console apps, Winforms, WPF, etc.  Since we’ve programmed to a contract (which is just an Interface), any class that implements the Interface can be a service.  This is powerful.  This is powerful because how we expose this service is up to us (again it is all about configuration).  Because we can expose our AirportService a number of ways we can see that WCF provides developers the ability to write code once and repurpose their code as needed. 

image

Exposing a WCF service requires a little more training from this point forward ( just like flying a 747) because we have to understand how to configure the service.  It is this little bit of extra effort required to understand WCF configuration that stops a lot of developers from using WCF.  This is a shame because when the developer using ASMX wants to guarantee message delivery, participate in transactions, or use binary serialization instead of XML, they’ve got a lot of work ahead of them as compared to WCF.   

The moral of the story is ASMX is simple and because it is simple, it isn’t very powerful.  Take the time to learn about WCF because this is the future of the .Net platform, thus it will be time wisely spent.  If you’ve been holding back I encourage you to step out of your old ASMX habits and learn the ways of WCF. 

If you would like to dig a little deeper with WCF I encourage you to check out my “Demystifying Windows Communication Foundation” power point.  In there you’ll find a lot more details about how WCF works.

http://keithelder.net/Presentations/DemystyfyingWCF/DemystifyingWindowsCommunicationFoundation.ppt

Happy messaging.

Aiptek HD 1080P Video Camera

Posted by Keith Elder | Posted in Mobile Devices | Posted on 14-10-2008

imageSeveral months ago I acquired a new video camera, the Aiptek HD 1080P.  If you aren’t familiar with this brand, don’t feel bad as I wasn’t either until a little over a year or so ago.  I haven’t owned a video camera in a long time and I honestly didn’t want to spend much on one knowing how little I would wind up using it.  The Aiptek fit perfectly into my price range and the features, well, they just can’t be beat for the price.

For starters, yes you read that correctly, this camera does 1080P.  Here are some specs that may be of interest.

image

I use a 4GB SanDisk Ultra II card in the camera which provides about an hour of high definition 1080P recording.  The camera saves files onto the memory stick in .MOV format (Quicktime).  This is good and bad.  It is good because you can drag the files directly to the computer and start playing them.  Some cameras have proprietary formats that force you to encode them which takes time.  The bad about having the video in .MOV format is it makes editing video really hard on Windows.  Movie Maker doesn’t support the .MOV format and I have had a hard time trying to figure out what to use to do editing.  As a matter of fact, I’m still trying to figure it out.

The video the camera takes really good video if there is good lighting.  It is horrible at night, don’t even try.  Thus, you wouldn’t want to take this to a night football game or soccer game.  If you have kids in sports, you should probably buy something else.  It is very portable and I have found it fits really good in my back pocket. 

One day I’ll produce some real video I’ve taken with the camera, but until then you’ll have to settle for “Deer in the backyard” to see a sample of the camera’s quality.  I shot this right before lunch today when I heard the dogs barking.  There are two fawns in the back yard wandering around.

This video was shot and the .MOV file transferred to my computer and then uploaded to Viddler (which has better quality than YouTube).  Nothing was done to it.  It should give you a good sample of the camera’s quality.

If you are looking for an economical camera that is cheap and records great video in good light this one may need to be on your list.

Balancing Readability and New Syntax Sugar in C# 3.0

Posted by Keith Elder | Posted in .Net | Posted on 08-10-2008

I’ve been struggling with something the past several weeks since I’ve been heads down programming some new features at work.  It is the first time in awhile I’ve really had a chance to dig in and use the latest and greatest features in .Net 3.5 and C# 3.0 in a production environment.  Like most developers, I find myself struggling to remember to use the new features in the language since I’ve been doing things the same way for years.    I have to constantly remind myself that I could do things differently than I’ve done them before.  Anonymous methods, automatic properties, lambda expressions, LINQ and other new features just to mention a few.

Here’s what I’m struggling with.  Where do you draw the line in the sand?  At which point do you say “Just because you can doesn’t mean you should?”.  In other words, how do you balance readability versus using new language features.  The absolute simplest example I’ve run across recently is as follows. 

I needed to get the first IP4 Address of the current machine.  A computer can have multiple addresses (not only IP4 but IP6 addresses too).  To start with I already had a method that would validate an IP4 address.  Here’s the method. 

   1: public static bool ValidateIP4Address(string ipAddress)
   2: {
   3:     string ipRegex = @"^(2[0-5]{2}|2[0-4]\d|1\d{2}|[1-9]\d|\d)\." +
   4:                     @"(2[0-5]{2}|2[0-4]\d|1\d{2}|[1-9]\d|\d)\." +
   5:                     @"(2[0-5]{2}|2[0-4]\d|1\d{2}|[1-9]\d|\d)\." +
   6:                     @"(2[0-5]{2}|2[0-4]\d|1\d{2}|[1-9]\d|\d)(?:/(3[012]|[12]\d|\d))?$";
   7:     Regex regex = new Regex(ipRegex);
   8:     return regex.IsMatch(ipAddress);
   9: }

As I solved this problem I knew what I wanted to do. I wanted to loop through all IP Addresses on the machine and take the first IP4 Address.  The solution is simple but it can be done numerous ways, especially when you start using new C# 3.0 features.  I started writing the code and here’s what I came up with using a Lambda expression (a new C# feature).

   1: private static void GetIpUsingLambda()
   2: {
   3:     string ipAddy = Dns.GetHostAddresses(Dns.GetHostName()).First(i => ValidateIP4Address(i.ToString())).ToString();
   4:     Console.WriteLine(ipAddy);
   5: }

After writing it I checked my unit test and it passed.  I then switched gears in my brain and starting looking at it as if I had seen it for the first time.  Sure it looks cool and complicated but what the heck is it doing?  There is a plethora of parentheses, nested methods and dots.  Honestly, it isn’t easy to read.  But it is in one line!

Then I rewrote it like this to hopefully make it more “readable”.

   1: private static void GetIpUsingLambda()
   2: {
   3:     string ipAddy = Dns.GetHostAddresses(
   4:                         Dns.GetHostName()
   5:                         ).First(
   6:                             i => ValidateIP4Address(i.ToString())
   7:                         ).ToString();
   8:     Console.WriteLine(ipAddy);
   9: }

Is it more readable?  I don’t know to be honest.  I’m struggling with it myself.  It is only marginally easier to read since it is somewhat broken up by the parentheses.

I decided to then write it “old school” just for comparison. 

   1: private static void GetIpOldWay()
   2:   {
   3:       IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName());
   4:       foreach (IPAddress addy in addresses)
   5:       {
   6:           if (ValidateIP4Address(addy.ToString()))
   7:           {
   8:               Console.WriteLine(addy.ToString());
   9:               return;
  10:           }
  11:       }
  12:   }

Line #3 gets all IP addresses on the machine.  Then we loop through each one calling ValidateIP4Address().  If we find a match we stop on the first one.

Here’s the question, which one is more readable and understandable at first glance, the lamba or the old way?  I’ll let you decide.

Of course we could take the GetIpOldWay() and throw in some new C# features using the keyword “var”. 

   1: private static void GetIpUsingVar()
   2:    {
   3:        var addresses = Dns.GetHostAddresses(Dns.GetHostName());
   4:        foreach (var addy in addresses)
   5:        {
   6:            if (ValidateIP4Address(addy.ToString()))
   7:            {
   8:                Console.WriteLine(addy.ToString());
   9:                return;
  10:            }
  11:        }
  12:    }

Really there isn’t much difference.  It is less typing for me the developer but that’s about it.  Not much difference.

One more way we could write this is using LINQ.

   1: private static void GetIpUsingLinq()
   2:  {
   3:      var ipAddy = Dns.GetHostAddresses(Dns.GetHostName());
   4:      var foo = (from i in ipAddy
   5:                 where ValidateIP4Address(i.ToString())
   6:                 select i).First();
   7:      
   8:      Console.WriteLine(foo);
   9:  }

Interesting.

For me the LINQ version above is the most interesting and I think the simplest to understand for someone looking at the problem for the first time.  I think it expresses more of the “intent” of what I was doing.  It is more typing compared to the Lamba expression in the GetIpUsingLambda() but it is easier on the eyes. 

After writing all four variations on this simple real world problem I think I like the LINQ example the best.  I am positive I’m not the only person out there struggling with this and I think it is a discussion that is happening in developers minds.  Of course this whole discussion is just personal preference but I think maintaining readable code is something we should strive for in our systems.  I also think if another developer had to change or modify the Lambda expression they’d spend a lot more time figuring out what it is doing compared to other samples, especially the LINQ example even though we are using new language features.

For developers throwing around Lambda expressions like they are candy I would question if it is truly the best and most maintainable code.  Just because you can doesn’t mean you should in all cases.  Definitely something to think about.  Feel free to weigh in, I’m curious as to which example you find the easiest to understand.

UPDATE:

Several of us on IRC continued this conversation there yesterday and I wanted to capture some of that conversation.

Jay Wren brought up using AddressFamily which in this example would be faster.  Here is a rewritten example using the Lambda expression using the AddressFamily enumeration.

   1: private static void GetIpUsingLambda()
   2: {
   3:     string ipAddy = Dns.GetHostAddresses(Dns.GetHostName()).Where(i => i.AddressFamily == AddressFamily.InterNetwork).First().ToString();
   4:     Console.WriteLine(ipAddy);
   5: }

Nate Kohari added onto Jay’s work and took on the challenge of readability by suggesting an extension method of IsIP4() for the IPAddress. 

   1: public static class Extensions
   2: {
   3:     public static bool IsIP4(this IPAddress i)
   4:     {
   5:         return i.AddressFamily == AddressFamily.InterNetwork;
   6:     }
   7: }

Adding the extension method would then allow the Lambda and the LINQ example to really flow.  They would now look like this.

   1: private static void GetIpUsingLambdaWithExtension()
   2: {
   3:     string ipAddy = Dns.GetHostAddresses(Dns.GetHostName()).Where(i => i.IsIP4()).First().ToString();
   4:     Console.WriteLine(ipAddy);
   5: }

   1: private static void GetIpUsingLinqExtension()
   2: {
   3:     var foo = (from i in Dns.GetHostAddresses(Dns.GetHostName())
   4:                where i.IsIP4()
   5:                select i).First();
   6:     
   7:     Console.WriteLine(foo);
   8: }

Now we are truly getting somewhere balancing the new features in C# 3.0 and readability.   This final LINQ version is the winner in my book although the Lambda example makes my geek senses start to tingle.

Like this article? kick it on DotNetKicks.com

Technorati Tags:

How To Solve Housing and Financial Crisis With Only $50 Billion

Posted by Keith Elder | Posted in General | Posted on 06-10-2008

I tend to stay out of two circles of public discussion, 1) politics and 2) world affairs.  But given our government spent $700 billion dollars last week makes me take up the keyboard and come to life. 

Dan Gilbert, the Chairman and Founder of Quicken Loans (full disclosure – I work for QL), and owner of the Cleveland Cavaliers, has a solution to the problem at hand.  It is a plan that, while lengthy, for me makes a lot of sense. 

It makes sense on a lot of levels including only costing $50 billion dollars instead of $700 billion dollars.  It makes sense because people can keep their homes and get more money circulating back into the economy.

Before you pass judgment, read the plan.   If you don’t know Dan, know that he’s a great thinker and a man that has a deep understanding of what is going on.  Also understand this plan is not just something Dan wrote down on a whim.  He’s been doing a lot of work on this with our Chief Economist Bob Walters and the Former Chairman and CEO of Pulte Homes, Jim Grosfeld. 

If you like the plan, let Dan know as well as others.  If you hate the plan, let Dan know.

Here is the plan:

http://choosethinking.com/2008/10/a-solution-that-works/ 

With the stock market today losing over 700 points we need to do something and fast.