Thursday, February 18, 2010

On The Importance of Code Reviews

From my "I wrote this a quite a while ago and never got around to posting it" collection...

I recently reviewed some code that contained a number of shared, global variables. Basically, a shared variable is re-used by all callers to the particular program in which it is defined. If one caller sets the value to “foo”, every other caller to that program will see the value “foo”. You could think of it as a chunk of shared memory that can be accessed by any instance of the program in which the variable is defined. A real world analogy might be an office bulletin board where every worker has access to read and post important news. That works fine if only one or two people are involved in changing the items posted to the bulletin board at any one time, but what if 100, 1000, or 10,000 people all tried to update the posted news items at the same time?

The shared variable feature of VB.NET can be used to great advantage because it allows us to perform long-running tasks only once and share the results across every caller. Thus, all but the very first execution will run much faster than they would if the long-running task had to be performed every time. That said, we also need to be very careful when implementing this technique (search for SyncLock for more information).

In the code I reviewed, every execution of the program was changing the values of the various shared, global variables, and this introduces a major issue. The problem is that every caller has the potential of overwriting the data of every other caller at points in time when this will cause errors or erroneous information to be returned. Due to the way applications are typically tested prior to reaching a production environment (very few users performing any given task), it is unlikely that such an issue would be found prior to it impacting end users. That is, unless you hold a code review attended by people that can find such a flaw and help come up with a solution. If the code in question had not been reviewed, I can say without a trace of exaggeration that the result would have been weeks to months of customer complaints about strange, intermittent errors. Numerous hours and dollars could have been wasted trying to track down and fix the problem. Instead, the problem was resolved prior to ever making it outside the development environment. This is just one reason why code reviews, when done properly and involving the appropriate participants, are an invaluable part of the development process. Every project should allow time in the schedule to both hold and react to the comments from code reviews.

It is important to note that a code review does not always have to be what one might typically envision (multiple people locked in a room for 60-90 minutes). The idea is just that every piece of code we write has been seen by at least one more set of knowledgeable eyes prior to being thrust upon the users. The number of reviewers should scale up for code that is more critical, complicated, or involves the security of a user's account and/or private information.

Monday, August 10, 2009

How to Get Your iPhone Photos to Sort Chronologically

Please note that I am using iTunes running on Windows Vista to sync photos onto my iPhone 3GS. Just a heads-up. Most notes will still apply to other setups.

I don't know about the rest of you, but I prefer all my photos to be sorted in chronological order. This is particularly true when it comes to my iPhone. I don't usually sit and watch a slide show or even flip through multiple pictures. What I often do, though, is think of a picture I want to show somebody and scan through my photo library (several hundred photos) until I find it. Having every picture sorted by the date it was taken makes this task much easier. I won't go into the intricacies of how iTunes decides to order your photos when putting them on the phone. I've done hours of experimenting, and the easiest thing to say is that it tends to sort of try to keep them in whatever order you sorted the folder the last time you looked at it in your Windows folder browser. I'm being intentionally vague here because that seems to be howApple decided to implement this feature. Whatever it really does (random number generation, contacting Steve Jobs behind the scenes for input, etc.) makes no sense at all, but it must be some strange interaction between iTunes and Vista.

Anyways, the solution I use is the following. Since I organize my photos with Google Picasa, I simply add all the pictures I want to put on my iPhone to an album for that purpose. Then, I select and export them to a single folder. During this process, I opt to shrink the photos down to a smaller size to conserve space. Regardless, these steps aren't that important. You just need to get all the photos you want on your phone into a single folder. Then, I rename the files with the date and time they were taken so that, when sorted by name (Windows default), they are in chronological order.

Of course, I don't sit there for hours renaming. There wouldn't be much point in blogging about that. I found a free program called Siren that can do it for me. Siren has many, many features and can be a little confusing to use at times, but I'll give you a simple command-line that you can execute. Let's assume that your photos are all .jpg and reside in a folder called "C:\Temp\iPhone Photos". Note that the folder should contain a COPY of your photos and NOT THE ORIGINALS just in case something goes wrong. You can run the following from the command line:

"C:\Program Files\Siren\Siren.exe" /D "C:\Temp\iPhone Photos" /N /E "%%Xdo.jpg" /S "*.jpg" /R /Q

It looks complicated, but all it does is execute Siren on the contents of the folder with a few key options enabled. Each .jpg file within will be renamed with the date and time (24-hour) the photo was taken. For example, a photo take August 2nd, 2009 at 8:41:46 AM would become "20090802_084146.jpg". Note that the date is in kind of a funky order (year, month, day) depending upon what you're used to. This is just so that Windows and iTunes/iPhone will sort it properly. That's all there is to it. You now have a folder of photos named in chronological order just waiting to be synchronized to your iPhone. You can add more photos later and run the program again.

PS - In the off chance that you somehow have two photos taken at the exact same second, I would just use a free program like Exifer to change the date/time metadata of one of the photos to be a second earlier or later.

Friday, January 23, 2009


Two posts on the same day! I just wanted to share some of my woodworking project photos available on Flickr ( For whatever reasons, I just never adjusted the security settings to open these to the public as all my photos are limited to friends and family viewing. I also have a couple of projects in the works. So, check back in if you're interested.

This is the home theater I built in my previous house a few years back.

Theater Final by cmaterick.


Finally on CodePlex

As demonstrated by my lack of blogging this past year, things have been pretty busy. I suppose that's just what happens when you've got a job, wife and kids, a house with things to fix, and a mild obsession with home automation and audio distribution that eats up all your free time.

This post is just to mention that, of all the little .NET programs I've written over the past few years, I finally have one that I think may really be useful to other folks. It's been my goal to get an open source project up on CodePlex, and now I have ( The name, MediaManipulator, isn't all that creative, I know. However, the tool is quite useful. It can do a couple different things including embedding your hi-resolution cover art from iTunes into your audio files (while alerting you of issues like missing music and artwork) and exporting playlists from iTunes while sorting the contents according to your specifications (artist, song name, etc.). Please check it out and let me know what you think. The code is tidy, but there's not a ton of commenting at this point. I have a few updates in mind for the next time I find a couple free hours.


Wednesday, November 26, 2008

Save 8% or More on eBay Purchases

NOTE: Since the % cash back you get it based-upon the keyword you use and your timing, I've written an application that puts the latest, highest % keyword into a twitter feed available at Look there to get the best keyword to use in the steps below.

For those who haven't used it, there is a site called Jellyfish through which you can get cash back for shopping at particular stores. Microsoft actually purchased them and turned it into the Microsoft Cashback program integrated with Microsoft Live Search. They are currently offering the following deal that gets you at least 8%, up to $200, on tons of ebay items. You can also use the offer up to 12 times for a maximum savings of $2400 reimbursed directly to your PayPal account!
  • Go to and set up a Microsoft CashBack account (just sign in with your Live ID and tell them your address).
  • Go to
  • Search for the keyword noted in bold purple at the top of this post to trigger a % off ebay offer (8% and up). Note you don't have to buy what you search for on Live. Once you get to ebay, you can search for and buy whatever you like.
  • If the offer is triggered, you will see a gray box that looks something like this. You may have to search multiple times to trigger the offer.
  • One or more of the links will take you to ebay (pick the one that has the highest % off) where you then have a 60 minute window to find and buy whatever product you like. As previously noted, your % off coupon has been triggered and you can now search for anything you like in ebay. Technically, you can find the product in advance and add it to your watch list instead of trying to beat the 60 minute clock. You need to use Buy It Now and pay via PayPal. On the page where you confirm your purchase after clicking the Buy It Now button, you will see how much cash back you are going to get (look because there are special instructions for some sellers). Don't worry, though, because you haven't agreed to purchase the item yet when you're on that screen. Confirm the purchase, check out, and follow the directions (you will need to click a link to Microsoft's CashBack site at the end to claim your cash back).
  • If the item has a return policy specified (in the return policy section of the listing not in the description), your cash back will become available 60 days later (they wait until you cannot return the item) in your Microsoft CashBack account and be automatically transferred to your PayPal account. If the item does not have a return policy, you get the cash back instantly in your PayPal account! Please note that I cannot guarantee this last statement if it's your first purchase using the offer as they may have a different rule for that. I have purchased 4 items so far and have received instant cash back on two of them (#2 and #4) ostensibly because they had no return policy.
So, you may get it instantly or you may have to wait a little while for the $, but 8-35% off a whole bunch of stuff is nice. Plus, your pending cash back shows up right away in your Microsoft CashBack account, so you're not wondering whether or not it worked. The cash back limits are $200 per purchase and up to 12 purchases per account. To make a second, third, etc. purchase, simply go back to and start over with a new search. Here are the official details.
Please note that nobody appears to know when this offer will end, but I can't imagine it will last beyond the holiday shopping season.

EDIT: Added details about instant cash back and being able to search for anything once you get to ebay regardless of what you search for in Microsoft Live Search. Added Magellan GPS search term. Added note about the keyword not being important but the timing triggering the different % savings.

EDIT: I made purchase number 12 with this offer. Upon attempting # 13, I was informed on the eBay checkout screen that I had already exceeded my lifetime limit for the deal.

Tuesday, November 11, 2008

Microsoft PDC 2008 - Better Late Than Never

By "Better Late Than Never, " I'm referring both to my delayed post and the fact that PDC was cancelled last year and rescheduled for this year. For those who don't know, PDC is the Microsoft Professional Developers Conference that was held in Los Angeles at the end of October (10/26 - 10/30). It is scheduled "as-needed" and provides Microsoft with a stage to unveil new platforms, tools, applications, etc. to a few thousand tech geeks and a bunch of press folks. I was mainly Twittering about it this year, so I'm a little behind on my blogging. Here's a recap of some of the main items introduced at the conference this year. Some of the information is a little fuzzy as the final workings of the technologies were not made 100% clear. It's possible that even Microsoft folks are a little unsure as well.

Microsoft Azure
Azure was the major unveiling for the conference. It is Microsoft's cloud computing platform and is somewhat similar to Amazon's EC2 with a Microsoft spin. Basically, Microsoft is ramping-up their data centers around the US (eventually around the world) to house tens if not hundreds of thousands of servers upon which Azure versions of all of their business platforms will be available. These include Live Services, .NET Services, SQL Services, Microsoft Dynamics CRM Services, and Microsoft SharePoint Services. You can then write applications that run locally and take advantage of any or all of these services running in Azure. Alternatively, you could host your entire application in the Azure cloud and not maintain local servers. The usage fees were not spelled-out, but there was reference made to each application being able to "expand" and "contract" automatically to satisfy user demand.

Windows 7
Although Windows 7 was already in the news, PDC was the first public unveiling of the Vista successor. Microsoft claims to have gone through every piece of Vista with a fine-tooth comb, from the kernel to the user interface, and tweaked just about everything. Here are some noteable items that were demonstrated during the keynote and subsequent classes.
  • The architecture for Windows 7 has been completely modularized allowing for custom versions to be easily assembled. For instance, Microsoft is planning to release a slimmed-down edition for netbook computers. Even the full version, with all the bells and whistles, requires far less horsepower to run than Vista.
    • I'm planning to install the pre-beta release of Windows 7 I received at the conference on an Acer Aspire One netbook with a 1.5GHz Atom processor and 1GB of RAM (once the PC arrives at my house this afternoon). To prove a point, Steven Sinofsky, the head of Windows development, has been running Windows 7 on a netbook with even lower specs as his primary PC for the last couple months.
  • Development is being synchronized with Windows Server 2008 R2 so that the two work in harmony with some of the new features.
  • The User Account Control (all those warning pop-ups) has been toned-down. It became clear that users either disabled UAC in Vista or became numb to it and approved everything. In Windows 7, it will be less annoying and customizable.
  • The Taskbar has been replaced by the Superbar. If you're familiar with Mac OS X, you will notice many similarities, but MS has taken things a bit further. Instead of trying to explain everything here, this site has a decent video that shows the Superbar along with the new Jumplist and Aero Peek features. Technically, there's even more to Aero Peek that allows you to get a full-size preview of the window as it would open on the desktop were you to click on one of the thumbnails. It also allows you to temporarily make a window transparent so that you can "peek" at what's behind it.
  • Aero shake is a very unusual feature that allows you to grab a window and shake it to minimize all other windows. Shaking the one window again will bring the others back
  • Notes for many more features are available online, but these are the main ones that were demonstrated.

Windows Server 2008 R2
A really interesting feature was introduced for both Windows 7 and Windows Server 2008. I'm including it here to make it stand out from the big list of Windows 7 items. Basically, Microsoft claimed that you will be able to boot a physical computer (destop or server) from a virtual PC instance that you've mounted as a mapped drive. It's a little difficult to explain what this means, but I'll try. Let's say you have a single server that's running several virtual servers and you're hosting a website that gets really busy at Christmas. To satisfy the demand, you want to set up an extra, physical server and dedicate it to the application (no virtualization). The idea is that instead of spending the time to install the application on the new server, you can simply put a copy of the virtual PC image on the server and then cause that server to boot to the OS, applications, etc. that are on the virtual PC image without actually running the virtual PC itself. It's as if the virtual PC image has become the C drive for that server. The same can be said for desktop applications. At the conference, we got a virtual PC image in which to test a beta build of Visual Studio 10. I can put that image on my netbook after installing Windows 7 and actually set the netbook to boot to the OS encapsulated within the virtual PC instead of booting to the typical OS and then running the virtual PC on top of this. Of course, this assumes that the feature is enabled in the Windows 7 build I have, but I'll know soon.

Live Mesh
Live Mesh is a synchronization framework that allows data to be shared across multiple devices (Windows, Mac, mobile). The Beta for this is actually available now. You can go to the Live Mesh site, sign up, register various machines, install the software, and set up folders to automatically synchronize across all of them and your online desktop. There is also an API for synchronizing application data. Read more about this in the Office 14 section below.

Visual Studio 10
Not too much was said about Visual Studio 10. Perhaps that is why they've already announced PDC 2009. Having two back-to-back is unusual since they are typically held at least 2 years apart. The only item of note that I have is that the new version of Visual Studio is actually built as a Windows Presentation Foundation application. It's good to see Microsoft really using its own tools. I believe that future versions of Office and other applications will also use WPF and .NET.

Office 14
Microsoft announced that mobile and online versions of Word, Excel, PowerPoint, and OneNote will be made available at the same time as the next desktop version of Office. The online versions are supposed to be cross-browser/cross-platform compatible. Also, all versions (local, online, and mobile) will be built using Live Mesh to allow document synchronization. They gave a demonstration of multiple people simultaneously working on the same document from a local copy, online, and via a mobile phone. They were able to collaborate and see eachothers' changes. For personal use, there will likely even be free versions of Office online available similar to Google Docs, Google Spreadsheets, etc., but the experience will be very similar to the desktop versions.
A really interesting feature is that corporate customers wishing to use Office online will have the ability to license and host their own versions (for data security). Depending upon the size of the company, this option could be significantly cheaper than buying licenses for desktop copies of Office for every employee while still being secure.

There were some interesting demos for the Microsoft Surface (table-top) computers both during key notes and spread throughout the conference. It's a very fun technology to play with, but I don't see too many practical applications yet. One keynote demo, however, showed a very fascinating take on the surface that allowed to to see one thing on the surface screen and something completely different on a screen held above the surface. I believe that was on Wednesday morning, and it's worth watching.

Microsoft is doing some very interesting things with their next release of ASP.NET AJAX. Without going into too much detail because nothing is finalized yet, they are basically adding a bunch of functionality that you would normally only find on the server end. This includes event handling, data binding, and more but written in such a way that it is completely compliant with XHTML and JavaScript standards. It's a little unusual to look at, but it functions simlar to .NET code on the server side. You create a control in HTML, use JavaScript to bind a datasource to it, and ASP.NET AJAX takes care of the rest (like requesting the data from the server, receiving the data back in JSON format, and then rendering the data as browser-compliant HTML). You can find out more at the ASP.NET AJAX website.

Microsoft Boku
For me, this was probably the most interesting keynote demo. Boku is a project from Microsoft Research that should be available early next year. It's basically a way to get people of all ages (particularly kids) interested in computer programming by allowing them to build their own games using a very clever, icon-based system that is all controlled using a gamepad (on a PC or an XBox 360). You really have to see the videos on the Boku site to understand, but I'm already looking forward to spending some time using it with my daughter so that she has a better understanding of computers and what her Dad does for a living. The depth of what you can build very easily without even using a keyboard is amazing.

Friday, June 6, 2008

Tech-Ed 2008

Last year around this time, I was posting a daily blog with photos and thoughts on the Microsoft Tech-Ed 2007 conference. This year, I'm at my last day of the Microsoft Tech-Ed Developers 2008 conference. I was so exhausted last year, that I skipped the daily blogging this year and took things easy in the evenings. However, I thought I would put up at least one post containing my thoughts on this year's extravaganza.

I'll start by saying that it wasn't the extravaganza that it has been in past years. They split the conference over two weeks, so there's only 6000 or so people here this week (versus 14,000 or so last year). That, perhaps combined with the general state of the economy, has lead to lots of very apparent cut-backs. Little things like the empty tables that used to be piled high with snacks and the lack of any drink choices beyond pop and coffee, while not the end of the world, were definitely noticeable. I also missed having the option of attending a couple of the IT Pro sessions to get a different perspective on things. There were only maybe 1/3 of the usual vendors on site, and none were giving away big prizes. Last year, there were thousands of dollars, a Ducati motorcycle, and more. The party at Universal Studios was OK, but it lacked the same spark as last year's event at Islands of Adventure. For one, Microsoft had only rented-out half of the park. Several rides, including The Revenge of the Mummy roller coaster (my favorite) were off-limits to us. On a side note, I have to point out that Universal calling the Simpsons ride "new" is quite an overstatement. They just put a paint job on the old Back To The Future ride, replaced the Deloreons with roller coaster cars, and changed the movie that plays on the screen. Other than that, it's the same ride. It would be like taking your car with 50,000 miles on it, painting it and installing a new exhaust, then telling everybody its a "new" car. But I digress... :)

That said, the real point of attending the conference was still of similar caliber to years gone by. There was a ton of stuff to learn and a bunch of really good (some not so much) sessions from which to choose. It still got me jazzed about all the latest Microsoft offerings just like it always does. If this had been my first Tech-Ed, I would have been overwhelmed and wowed just like I was several years ago when it WAS my first Tech-Ed. However, the feel just wasn't the same this year. All things considered, I'm sure I'll be back again. My guess is that the Developer week of the show will continue to grow in size and I will, once again, be wowed.

PS - I almost forgot to add my usual plea to Microsoft. I submit this same request as part of every evaluation for every session.... "Slides should be made available prior to presentations to facilitate note-taking particularly by folks with tablet PCs. I've been asking for this for years, and I just can't understand why it never happens. If the slides are required in advance of the conference, why can't they be made available before the sessions? If you're looking to sell tablet PCs and copies of OneNote or Office with OneNote, this would be a perfect way to advertise their functionality. Print the PowerPoint to OneNote and write your thoughts right on the slides as the presenter is talking. It gives your notes much more context when you go to review them after the conference."