Worst Code Ever!

June 16th, 2009

First take a look at what the offending code that I have to maintain looks like, then I’ll explain.

public IList<Product> ListProducts(string filter)
{

IList<Exception> exceptionResults = new List<Exception>();

List<List<Product>> products =

handlerMultiCaster.Handle<List<Product>>(out

exceptionResults, “TRD.LISTPRODUCTS”, distributionPoint, filter);

if (products.Count == 1)
{

return products[0];

}
return
null;

}

So the first thing to notice about this code is that there are two main concepts, a “multi caster” and a “handler”.  “Handlers” have only one method called Handle() and you pass a magic string telling it what exactly to “handle”. This in itself is terrible because a developer has no idea what the possible values of what they should pass are unless they dig down into the Handle method to find where the other magic strings are stored.  “Handlers” are configured through an arcane configuration framework that loads .dlls with concrete implementations of the Handler that have such methods as Invoke() and DoHandle().

Now it gets even better with the “multi caster”.  In an application there may be any number of “Handlers” configured and since these handlers get invoked dynamically(something any other dependency injection framework could have done better) the best thing that the “multi caster” can do is to loop over all configured handlers and call Handle on ALL of them(whether they’re actually going to work or not).  This is the really hilarious part where the IList of Exceptions comes into play.  Since the multi caster just calls all the handlers blindly most are bound to fail and throw exceptions(there goes performance), so it returns a list of all those exceptions.  What to do with all those exceptions is anyone’s guess.  What’s worse is when the so called multi caster rips through each handle method some of them could get part way through execution and then throw leaving multiple handlers in an unkown state, perfect!  The last part is just really annoying, if you only need one list of products, why return a list of lists of products and then just to add salt to the wound by only grabbing the first list out of the list of lists.

There are so many anti-patterns here it makes my head spin, but nobody else seems to think it’s a backwards way to accomplish something.

The Big Picture

January 26th, 2009

If you’re like me and like to see big pictures, you need to check out this blog from the boston globe http://www.boston.com/bigpicture/ It’s definitely one of my favorites.

Emails!

January 9th, 2009

Our company recently switched email domains, so to keep my old email address forwarding correctly I have to maintain the old account also.  The problem is that I haven’t looked at it in a couple months.  To my surprise I logged in today and found this:

My inbox after 2 months

Close to 60,000 emails!  Granted, lots are error emails from our systems, but that’s still a lot of crap to sift through.  Which reminds me of a great article about email I read recently at coding horror. I may never get out from under the pile.

Cat riding a Roomba

November 20th, 2008

Although my wife would disagree, this is why cats are awesome.

Great CSS Tool

November 17th, 2008

I was alerted of this great tool last week that helps when you’re having problems with CSS based layouts.  Check it out http://giveupandusetables.com/ It’s a timer that tells you when you’ve spent too much time trying to get your css layout to work in all browsers.

Save the Kids

November 15th, 2008

I’m not sure whether to laugh or cry?

Rabbit Kid

Cat Kid

Human Resources 2.0

January 27th, 2008
class HumanResources
{
    private double revenue = ConfigurationSettings.AppSettings["InitialStartupCapital"];          

    static void Main(string[] args)
    {
        while (revenue > 0.0)
        {
            if (DateTime.Now.DayOfYear == 1) // first of the year
            {
                ChangeBenefitProvidersAndMakeEmployeesFillOutPaperwork();
                Console.WriteLine("We're excited to offer these new and exciting benefits!");        

                // calculate new revenue
                revenue -= ThisYearsRevenue() - LamePartiesFund() - DiversityFund();
            }
            else if (DateTime.Now.Day == 1) // first of every month
            {
                PlanLameParty();
                Console.WriteLine("We're excited to offer these fun events this month!");
            }
            else if (DateTime.Now.Month % 3 == 0 && DateTime.Now.Day == 15) // quarterly
            {
                MakeEmployeesFillOutMeaninglessGoalsAndBaseTheirBonusesOnThem();
                Console.WriteLine("We're excited to help you succeed in your career growth!");
            }         

            Thread.Sleep(TimeSpan.FromDays(1)); // sleep until tomorrow           

        }          

        Console.WriteLine("We're sorry, you've been laid off.");
        return 0;}
    }           

Gambling Problem

December 24th, 2007

It all started out with $50 that my roommate Andy owed me. While we were driving to get some delicious Chipotle, Andy remembered that he owed me money from when I sold him my old phone and jokingly asked if I wanted to be paid in scratch lottery tickets. I laughed and told him, “yeah, why not?” and then we ate our huge chipotle burritos(mine of course had no beans because that would just be gross). A couple weeks later Andy was headed to the bank and said, “Are you sure your really want $50 worth of scratch tickets?” I had almost forgotten about it, but still stuck with my first answer. I told myself it’d be like an experiment or at the very least a good story. So a few hours later Andy walked into my room with $50 worth of scratch tickets.

Scratch Tickets

Read the rest of this entry »

San Francisco

October 27th, 2007

Just got back from a business trip to San Francisco for the CTIA conference.  It was my first time to the Bay Area and I was impressed to say the least.  There were so many places I wanted to see and take pictures of, but I only had a few days there which were mostly filled with meetings/conference doings.  I was able to get a little time out exploring though, check out the photos

Chinatown Entrance

Global Warming?

October 4th, 2007

Ok, so those that know me know that I like to make fun of the whole global warming thing.  I think it’s slightly comical how much misleading goes on, on both sides of the argument.  Don’t get me wrong, I love the environment, I really do(camping, whitewater kayaking, etc.).  But here’s the thing; “saving” the environment is great insofar as it pertains to humans using it and enjoy it.  There seems to be this sentiment going around that we’re doing it “for the environment.” As if the environment is more important than the people living in it.  We obviously need to think about the environment and how we impact it for our children, but it’s just crazy thinking that a tree or rock or field is more important than a person.

This shirt that was given to me by a friend sums up my feelings on the matter.  It’s could go either way, you decide.

This is why I’m hot