Feb 12, 2011

Code Reviews Are For Critics

0 comments Links to this post
OK, so this is coming from a need to redeem myself. I screwed up and the only way that this will stop making me so miserable is if I help another developer not make the same mistake and then have to suffer the consequences such as being jolted out of sleep at 5 AM on a Saturday by a nightmare where you are being surrounded by Int32s overpowering you with the help of the Convert method and trying to change the Real you in to one of them. Its all over in a fraction of a second and you are now an Int32, you've either lost something that was yours or you've acquired some of their characteristics, you'll never be the same, you have been assimilated, you are now... well, them!!.


The Cast in My Dream


So this is how I screwed up.

I wrote
BillAmount = convert.ToInt32(row["bill_amount"]);
instead of
BillAmount = convert.ToDouble(row["bill_amount"]);
when hydrating an object with the data coming back from a stored procedure.
(Writing those lines again just gave me the shivers and I'm a little queasy.)

The erroneous cast of course rounded the cents in the amount so if the amount was $4.95 it now ended up being $5.00 or if it was $4.45 it would now be $4.00.

The Bug In the Machine

Salad, Alien Made Out of Vegetables by Till NowakSo now that we know how I screwed up...the question now is why didn't I see this before I even committed the code? This could have been caught before we went to production with this... ya we did .. we found the damn bug scurrying around in our production machines and killed it there before it turned dark green, grew fangs and a pointy tail and ate the pilot.

So the world is now safe from that monster ... but why did we miss it in the first place? we had the processes in place to catch these things before they go out to production, we wrote the unit tests, documented the project, did the code review, went through QA, passed the Certification Tests, and finally deployed to production after a pretty intense and rigorous process.


Tracking The Bug

I think the answer lies in how we finally found the bug. As the saying goes, the devil is in the details, sadly not all details are of immediate concern to everyone on the project, and among the myriad of things that can go wrong in a software project it is easy to miss several important but minor details.

An easy way In my opinion to get these details straight could be to have a check list that should be gone through at every stage in the life cycle of the project. I know, we don't need another document, and another process to follow, however if we think about it all this Check list is, is the requirements in a condensed format.

The check list should just be a set of expectations/issues that the software project has to resolve. This check list should be written by each stake holder in a project at the beginning of the project and updated as/if expectations/requirements change during the course of the project. Some or most of these could even be translated in to unit tests that would ensure that the goals are being met.

This check list should be used by each stake holder at various stages in the project's life cycle to then verify that his/her expectations are being met and if not then require that the cause be investigated until a satisfactory answer is received. That is to say If Ya See Something SAY Something! (That is essentially how we found the bug! Someone saw the problem and asked the question.)

The point of the checklist is to keep track of the details and to have a mechanism so they are tracked. This check list could be something that each stake holder goes through at the end of a design review, code review, QA test plan and product Demo. I don't think it should be the only focus of the stake holder as this will tend to limit the scope of say a design review or code review to just those set of concerns and could cause other issues to be missed.

The sign off to production should include the items on each stake holder's check list being checked off or crossed off. No item should be left unaddressed.

Critics Rule

It is imperative for a software team to have the resources and the process in place to identify and fix bugs. However this wouldn't mean much without a critical approach.

This is exactly the reason why a developer must not QA his/her own code, the point is that someone other than the developer should take a more critical view of the code and thereby help prevent bugs in the system.

The normal process is to have meetings to review the code that has changed and then sign off on the code once it is found that the accepted coding practices have been followed and that nothing has been overlooked. This is meaningful only if the team in the room is paying attention, is knowledgeable and critical.

Alternatively it could be useful for one to hand over the code to another developer to review, run unit tests, evaluate aspects of the code that are not easily done by automated build tools such as test the logic and recommend a better way of doing something, read the documentation in the code to ensure it is understandable, etc.

Regardless of how this is done it is imperative that code is read and critiqued before it moves out of dev.

May 1, 2009

The World Is Flat

0 comments Links to this post

I came across this video while browsing through MIT’s open courseware. An excellent lecture by Thomas L. Friedman form 2005 about everything from the start of Netscape to outsourcing, politics, software etc. Its startling how relevant this talk still is and what a visionary he is.  

More here http://mitworld.mit.edu/video/266

Apr 16, 2009

C# TitleCase function doesn’t do the job

0 comments Links to this post
The TitleCase function in C# doesn’t always work if you don’t provide the CultureInfo string e.g “en-US”. But even when you do, it does not correctly format strings such as McDonald or O’Connor. The title case function would just return Mcdonald or O’connor. The following function correctly capitalizes the appropriate letters and will also exclude letters from the string that should not be capitalized.

For instance the following string
o’lunney’S bar and grill is across from mcdonald
is correctly formatted as
O’Lunney’s Bar And Grill Is Across From McDonald


/// <summary>
/// Capitalize the first character of all words in the given string
/// </summary>
/// Text to format as string
/// Returns the formatted text
public static string InitCap(string textToformat)
{
string pattern = @"\w+\W+";
string result = "";
Boolean capitalizeNext = true;
foreach (Match m in Regex.Matches(textToformat, pattern))
{
// get the matched string
string x = m.ToString().ToLower();

// if the first char is lower case
if (char.IsLower(x[0]) && capitalizeNext)
{
// capitalize it
x = char.ToUpper(x[0]) + x.Substring(1, x.Length - 1);
}
// Check if the word starts with Mc
if (x.Length > 3 && (x[0] == 'M' && x[1] == 'c' && !String.IsNullOrEmpty(x[2].ToString())))
{
// Capitalize the letter after Mc
x = "Mc" + char.ToUpper(x[2]) + x.Substring(3, x.Length - 3);
}
if (capitalizeNext == false)
capitalizeNext = true;
// if the apostrophe is at the end i.e. Andrew's
// then do not capitalize the next letter
if (x[0].ToString() == "'" && m.NextMatch().ToString().Length == 1)
{
capitalizeNext = false;
}
// collect all text
result += x;
}
return result;
}

Feb 24, 2009

Windows 7

0 comments Links to this post
Ive been running windows 7 in a virtual machine (Microsoft VM SP1) on my IBM Thinkpad for the past couple of weeks. The virtual hard disk is on an external 7200 RPM Western Digital My Book drive that is connected to a USB 2 hub. The host operating system is Win XP SP3. The VM is set to use 1gb of the host OS's memory instead of the default 512 kb and is set to access a shared folder on the host and also the host machine's wireless and wired network adapters.

The first thing I noticed about windows 7 is that compared to Vista, Win7 is lightning fast!
I still don't care for the UAC prompts, they are just as intrusive and annoying as they were in vista. Other than that I love the clean no nonsense interface. I love the fact that they got rid of the side bar that was in vista. The operating system its self seems quite stable, In fact given that it is still in a beta stage, I expected to have lots of problems setting it up in a VM environment, including problems accessing the shared folders and devices on the host system. I was pleasantly surprised when it installed smoothly and had no issues what so ever accessing drives or devices including the network adapters. As a matter of fact I haven't had it crash or blue screen even once in the past 2 weeks that I have been using it! Windows 7 comes with the beta version of IE8 and after the initial set up I was able to install and use all of the regular plugins such adobe flash, windows media player, Quicktime etc.

My next test is to start doing some development on it and test drive visual studio and few other dev tools on it. For those who are interested here is a link to the Windows 7 developer Guide
http://msdn.microsoft.com/en-us/windows/dd206698.aspx

Cheers!

Feb 2, 2009

Microsoft Business Rules Framework

0 comments Links to this post
Came across this fantasitc article by Rick Garibay on programming with the Microsoft Business Rules Framework that has made this somewhat exotic techonology (for me atleast) more hands on.

Dec 18, 2008

PowerCommands for Visual Studio 2008

0 comments Links to this post
I recently came across an article on Dev Source about Power commands for visual studio 2008 and was intrigued to see what was in this bag of tricks. The article written by John Mueller is an excellent introduction and I found it to be a much better introduction to the toolkit than the documention itself.

PowerCommands definitely helps you get more from Visual Studio by extending the functionality that Visual Studio provides. If you are an ardent user of ReSharper like me I found that it did add a lot of functiontions that just arent available with ReSharper such as the function to copy a project as a as project reference, Edit a project file etc. Some functionality on the other hand is duplicated like the ablity to sort and remove unused using statements (CleanUp code in ReSharper)

Overall I like the tool kit and it is proving to be quite a time saver. It does tend to make your context menus fairly long though if you also have Resharper.

You can Download PowerCommands for Visual Studio 2008 here.

Jun 2, 2008

2012: The Year The Internet Ends

0 comments Links to this post
How the industry will kill the Internet in about 4 years from now.
http://ipower.ning.com/netneutrality
A friend sent me a link to this. A lot of what is said there is pretty far fetched however I must admit even the thought of an ISP adopting a cable provider's business model to provide access to the internet is scary. Can you imagine an ISP saying you can access 200 more sites for $39 a month :)

For those of us in the US and the western world having unlimited internet access is almost a given, and choosing ISPs over who provides the highest speed and features such as a fixed IP, phone, TV, etc is taken for granted .

You may find it interesting that on the other side of the world in India for instance access to the internet is limited for the average home user, not by the number of websites you visit but but the amount of bandwidth you are allowed to consume! usually this is to about 256 mb per month! So though this does not go as far as saying what sites you can and cannot access it does limit your access to a lot of rich content.

In all fairness though these limitations are due to the limited bandwidth and infrastructure that is available. Can you imagine the chaos it would cause if ISPs here started doing that?
I shudder at the thought.

read more digg story

Feb 7, 2007

Doing Objects in Visual Basic 2005

0 comments Links to this post
Deborah Kurata's new book is out on safari (http://safari.informit.com/) before it is released to the stores on the 28th of Feb 2007. I couldn't find the the sample code for the book on safari's website and the book directs you to http://www.insteptech.com/ ,which, I think is a poorly constructed site cobbled together on frontpage. Anyhow, the sample code isn't there and whats more there is no mention of the book either. Weired.

The book The Addison-Wesley Microsoft Technology Series Doing Objects in Visual Basic 2005
itself is a great intro to object oriented development in Vb 2005 and the whole concept of binding controls to objects is just fantastic. The book examines this topic in depth and also details various pros and cons of binding different controls.

Im still reading the book but the material presented in it so far has been so good I cant wait to put the stuff I learn in to practice.

Ruins At Hampi