Aiptek HD 1080P Video Camera

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

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

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. 

Deep Fried Bytes Episode #14: LINQ’ing the Future of Development with Jim Wooley

 Listen To This Episode

http://deepfriedbytes.com/podcast/episode-14-linq-ing-the-future-of-development-with-jim-wooley/

 

How do you thinq…. uh… I mean think?  Do you THINQ in LINQ?  What about the KINQS in LINQ?  Are you the LINQ KINQG at the office? 

We sat down with the author of LINQ in Action, Jim Wooley, in the latest episode of Deep Fried Bytes

I’ve known Jim for several years now and believe it or not we are almost a mirror of each other as you’ll hear in the beginning of this episode.  This is a great show because LINQ really is a great killer cool awesome useful technology.  Our goal of this episode was to help developers work out the KINQS in LINQ.  Elly Mae is back and kicks the show off!  Enjoy.

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!

One More Year

Just this morning I got an email stating I was renewed for my MVP award!  There is a change though.   The award is no longer in the “Client App Dev” category.  I am currently in the “Connected Systems Developer” category. 

What does this mean?  Well, it just means that my focus the past year has been more on things like Workflow Foundation, WCF, and others.  I think this category is a better fit, especially for my current role at work. 

A big thanks to Microsoft for this recognition, it is truly an honor.  

«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678