• images
  • January 18, 2008

This morning, Micah was holding Miriam while doing his reading assignment. Later he was asked in his English assignment to write a descriptiive paragraph and here is what he wrote.

A young child makes time go backwards. When you hold her, warmth bursts into your body. She is a rainbow, and her eyes are always watching. She removes your frowns and gives smiles to the world.

  • images
  • December 19, 2007

12-15-07_0610.jpg
Saturday morning at a timely 5:59am, we welcomed our newest daughter. She showed up 3 weeks early weighing 6 pounds 12 ounces and was 18 inches long. This has probably been the most difficult pregnancy that Lisa has had and so this conclusion has been a bittersweet blessing.
dsc00099.JPG

  • images
  • December 4, 2007

Coding Styles can be an almost religious issue among programmers and so I begin this post with a little trepidation but as I have been asked to document my particular coding style for my former team before I move on to a new team next week, I thought it would be best to do it as a post to my blog. In the over 20 years that I have been programming my style has only changed a few times. The first programming language I was ever formally taught was PASCAL so the issue of where to put curly braces has always been settled in my mind and I won’t be discussing that here. What I do want to discuss is code flow. All through high school, college and my first several jobs in the computing industry I used a code flow like the following sample.

HRESULT DoBazThroughFooAndBar()
{
IFooThings* pFooThings = NULL;
  HRESULT hr = GetFooThings(&pFooThings);
  if (SUCCEEDED(hr))
  {
  IBarThings* pBarThings = NULL;
  hr = pFooThings->GetBarThings(&pBarThings);
  if (SUCCEEDED(hr))
  {
IBazThings* pBazThings = NULL;
hr = pBarThings->GetBazThings(&pBazThings);
if (SUCCEEDED(hr))
{
hr = pBazThings->DoSomethingProfound();
pBazThings->Release();
}
pBarThings->Release():
}
pBarThings->Release();
}
return hr;
}

This type of code flow should be very familiar to every developer out there. The only disadvantage to using this type of style is that complex functions will typically nest to absurd levels and that can make the code very difficult to read. The first change to my coding style happened when I joined Microsoft back in 1994. I came to work on the MFC team. Unlike most development teams at the time, MFC had the distinction of shipping not only binaries, but the source as well. Consequently, the team a developed very rigorous style guidelines well before I arrived. These guidelines abhorred the kind of nesting demonstrated above and instead opted for a code flow like the following sample.

HRESULT DoBazThroughFooAndBar()
{
CComPtr<IFooThings> pFooThings;
HRESULT hr = GetFooThings(&pFooThings);
if (FAILED(hr))
return hr;

CComPtr<IBarThings> pBarThings;
hr = pFooThings->GetBarThings(&pBarThings);
if (FAILED(hr))
return hr;

CComPtr<IBazThings> pBazThings;
hr = pBarThings->GetBazThings(&pBazThings);
if (FAILED(hr))
return hr;

hr = pBazThings->DoSomethingProfound();
return hr;
}

The thinking here was that since MFC was a class library we can assume that the programmer is using C++. So any type that needs to be cleaned up after being used should be wrapped in a class so it’s destructor can do the cleanup. This made the code much more readable. However, it had a few disadvantages. First, you often needed to implement one off classes to wrap types that needed to be cleaned up or alternately spend time looking for pre-existing wrappers for HANDLEs, HWNDs, HBITMAPs, not to mention memory that needed to be freed using delete, free, HeapFree or CoTaskMemFree. Because this isn’t always practical you would often end up with one or two types that were not wrapped and needed to be cleaned up inside of each FAILED case. This became a problem when code analysis tools hit the scene. Around 2002, it became vogue at Microsoft for the test team to measure the success of their automated tests by using code coverage tools to analyzed the percentage of code that was exercised. I remember one tester being particularly frustrated with me because he couldn’t get better than 40% of my covered because of all the error handling code to handle errors that almost never happened. The other disadvantage came when you needed to debug your application or instrument it with tracing since it was virtually guaranteed that you would have way more than one exit point within the function. So if you had a macro for tracing that needed to be placed at the beginning of every function and another one at the end, you would need to invoke that macro at every return. Consequently, this style was not popular outside of MFC. Instead most teams opted for a code flow like the following sample.

HRESULT DoBazThroughFooAndBar()
{
IFooThings* pFooThings = NULL;
HRESULT hr = GetFooThings(&pFooThings);
if (FAILED(hr))
goto Cleanup;

IBarThings* pBarThings = NULL;
hr = pFooThings->GetBarThings(&pBarThings);
if (FAILED(hr))
goto Cleanup;

IBazThings* pBazThings = NULL;
hr = pBarThings->GetBazThings(&pBazThings);
if (FAILED(hr))
goto Cleanup;

hr = pBazThings->DoSomethingProfound();

Cleanup:
if (pBazThings != NULL)
pBazThings->Release();

if (pBarThings != NULL)
pBarThings->Release():

if (pBarThings != NULL)
pBarThings->Release();

return hr;
}

Those who practice the art of programming and can trace their methodological lineage back to the school of the great Edsger W. Dijkstra) will immediately chaff at the thought of using gotos in their code. Consequently, many have sought other code flows that solve the same problems without the gotos. One in particular looks like the following sample.

HRESULT DoBazThroughFooAndBar()
{
IFooThings* pFooThings = NULL;
IBarThings* pBarThings = NULL;
IBazThings* pBazThings = NULL;
HRESULT hr = S_OK;
do
{
hr = GetFooThings(&pFooThings);
if (FAILED(hr))
break;

hr = pFooThings->GetBarThings(&pBarThings);
if (FAILED(hr))
break;

hr = pBarThings->GetBazThings(&pBazThings);
if (FAILED(hr))
break;

hr = pBazThings->DoSomethingProfound();
}
while(false);

if (pBazThings != NULL)
pBazThings->Release();

if (pBarThings != NULL)
pBarThings->Release():

if (pBarThings != NULL)
pBarThings->Release();

return hr;
}

While it very cleverly coaxes a goto out of a loop, I dislike it for exactly that reason. A loop should be used for looping, not faking a goto semantic. Since code is read many more times than it is written, I believe a programmer should strive to make the code as obvious and readable as possible. Using the above trick may confuse the casual observer and risks making it hard to maintain even for the seasoned developer. Notice particularly that variables that require cleanup must be declared outside the loop.

I finally converted (see I told you it was religious) over to the style I use today after I realized that it addresses all the issues above. Not only that but using my style will get you near 100% code coverage as the successful execution path hits every line of code. Here is a sample using my current style.


HRESULT DoBazThroughFooAndBar()
{
IFooThings* pFooThings = NULL;
HRESULT hr = GetFooThings(&pFooThings);

IBarThings* pBarThings = NULL;
if (SUCCEEDED(hr))
hr = pFooThings->GetBarThings(&pBarThings);

IBazThings* pBazThings = NULL;
if (SUCCEEDED(hr))
hr = pBarThings->GetBazThings(&pBazThings);

if (SUCCEEDED(hr))
hr = pBazThings->DoSomethingProfound();

if (pBazThings != NULL)
pBazThings->Release();

if (pBarThings != NULL)
pBarThings->Release():

if (pBarThings != NULL)
pBarThings->Release();

return hr;
}

  • images
  • September 25, 2007

It’s been a while since a comic has made me laugh out loud, but this one did it for me.

  • images
  • September 8, 2007

warning.GIFSo I come home from work yesterday evening. I’ve been working late this first week in Septemeber and probably will be for the next 6 weeks or so. Anyway, as I come through the garage door I see a curious sign posted over (yes over) our bathroom door downstairs. I mention this to my wife and she calmly explains that Lydia (our three year old) had zealously tried to help the family by cleaning the downstairs bathroom. In the process she half emptied an aerasol can of Lysol disinfectant spray. (this has instigated some serious training and retraining). Micah (my 11 year old) became concerned that exposure to such a high concentration (apparently it freshened the entire house for several hours) of chemicals might cause health concerns and so he posted this sign on his own initiative.

  • images
  • August 22, 2007

This is soo cool! I can think of all kinds of uses for this.

Update a photoshop plugin to do this is now available.

  • images
  • August 4, 2007

Summer is in full swing here and so I haven’t had much time to do anything out on the internet but I did want to share a very cool couple of videos. My kids really want to try this at home. They are trying to convince me that it is a good homeschool science project.

I recently received and e-mail that was part of a phishing scam asking me to login to my Paypal account. Of course the link provided actually went to a webpage (probably stolen) of a DSL customer of SBCGlobal. So I forwarded the email to SBCGlobal so they could investigate and I received the email below back from them this morning. As I read through it, I was really impressed at how much useful information they had assembled and provided in one place. So I am posting here and publicly giving them one big thumbs up!

—–Original Message—–
From: AT&T Internet Customer Care Security Team [mailto:abuse@sbcglobal.net]
Sent: Friday, June 29, 2007 5:31 AM
To: Sean Kelly
Subject: AT&T Internet Service Security Department

Hello,

AT&T Internet Services wants you and your family to enjoy the time you spend online. Unfortunately, these scams occur every day and the forgers may choose a variety of different businesses to impersonate. Fake emails have been discovered from banks, mortgage companies and even Internet service providers. Ultimately, you are in the best position to safeguard your personal information from these types of attacks.

How to Protect Yourself

1. Never provide your personal information in response to an unsolicited request, whether it is over the phone or over the Internet. E-mails and Internet pages created by phishers may look exactly like the real thing. They may even have a fake padlock icon that ordinarily is used to denote a secure site. If you did not initiate the communication, you should not provide any information.

2. If you believe the contact may be legitimate, contact the financial institution yourself. You can find phone numbers and Web sites on the monthly statements you
receive from your financial institution, or you can look the company up in a phone book or on the Internet. The key is that you should be the one to initiate the contact, using contact information that you have verified yourself.

3. Never provide your password over the phone or in response to an unsolicited Internet request. A financial institution would never ask you to verify your account information online. Thieves armed with this information and your account number can help themselves to your savings.

4. Review account statements regularly to ensure all charges are correct. If your account statement is late in arriving, call your financial institution to find out why. If your financial institution offers electronic account access, periodically review activity online to catch suspicious activity.

You Can Fight Identity Theft:

Never provide personal financial information, including your Social Security number, account numbers or passwords, over the phone or the Internet if you did not initiate the contact.

Never click on the link provided in an e-mail you believe is fraudulent. It may contain a virus that can contaminate your computer.

Do not be intimidated by an e-mail or caller who suggests dire consequences if you do not immediately provide or verify financial information.

If you believe the contact is legitimate, go to the companies Web site by typing in the site address directly or using a page you have previously book marked, instead of a link provided in the e-mail.

If you fall victim to an attack, act immediately to protect yourself. Alert your financial institution. Place fraud alerts on your credit files. Monitor your credit files and account statements closely.

Report suspicious e-mails or calls to the Federal Trade Commission through the Internet at http://www.ftc.gov/bcp/edu/microsites/idtheft/, or by calling 1-877-IDTHEFT.

What to do if you fall victim:

1) Contact your financial institution immediately and alert it to the situation.
2) If you have disclosed sensitive information in a phishing attack, you should also contact one of the three major credit bureaus and discuss whether you need to place a fraud alert on your file, which will help prevent thieves from opening a new account in your name. Here is the contact information for each bureau’s fraud division:

Equifax
800-525-6285
P.O. Box 740250
Atlanta, GA 30374

Experian
888-397-3742
P.O. Box 1017
Allen, TX 75013

TransUnion
800-680-7289
P.O. Box 6790
Fullerton, CA 92634

3) Please contact your local police department.
How to report if you have been a victim of an online shopping fraud:

If you have problems during a transaction, try to work them out directly with the seller, buyer or site operator. If that doesn’t work, file a complaint with the Attorney General’s office in your state. You can find your state Attorney General’s contact information on the website of the National Association of Attorneys General. www.naag.org

Online Shopping Tips:

Know who you’re dealing with. Anyone can set up shop online under almost any name. Confirm the online sellers physical address and phone number in case you have questions or problems. If you get an email or pop-up message while you’re browsing that asks for financial information, don’t reply or click on the link in the message. Legitimate companies don’t ask for this information via email.
Do not send cash, checks or money orders under any circumstances:

Pay by credit or charge card. If you pay by credit or charge card online, your transaction will be protected by the Fair Credit Billing Act. Under this law, you have the right to dispute charges under certain circumstances and temporarily withhold payment while the creditor is investigating them. In the event of unauthorized use of your credit or charge card, you generally would be held liable only for the first $50 in charges. Some companies offer an online shopping guarantee that ensures you will not be held responsible for any unauthorized charges made online, and some cards may provide additional warranty, return, and/or purchase protection benefits.

How to report if you have been a victim of an online shopping fraud:
If you have problems during a transaction, try to work them out directly with the seller, buyer or site operator. If that doesn’t work, file a complaint with the

Attorney General’s office in your state. You can find your state Attorney General’s contact information on the website of the National Association of Attorneys

General. your county or state consumer protection agency. http://www.naag.org/

Most answers to your questions can be found at http://helpme.att.net/.

Security viewlets, Firewalls, Phishing Alerts and Spyware removal tools are some ways AT&T Internet Services is making your Internet safer.

  • images
  • June 28, 2007

What American accent do you have?

Your Result: The West

Your accent is the lowest common denominator of American speech. Unless you’re a SoCal surfer, no one thinks you have an accent. And really, you may not even be from the West at all, you could easily be from Florida or one of those big Southern cities like Dallas or Atlanta.

What American accent do you have?


I agree with the conclusion, I just don’t like the way they worded it. I guess I don’t stand out in a crowd.