A builder sits you down at a table. "I want to show you something," he says, setting a rolled-up sheet of worn leather on the table in front of you. He reaches into his pocket, producing a single screw.

"I keep seeing these," he says, "and they're so hard to work with! I use my hammer to drive them in, but they don't work as well as nails. And once I finally get them in, the claw can't get under the head if I have to remove them." You start to feel embarrassed for the builder.

"It was then that I noticed this cross-shaped groove in the tip. And that's why I built..." he pauses as his eyes widen. He unrolls the clanking roll of leather, revealing hundreds of homemade screwdrivers. "...the grooved nail turning driver tool!"

"But..." you say, "couldn't you just has easily have bought a screwdriver?"

The builder blinks.

This describes how Trond N. felt, reviewing a co-worker's 32,498-line code file, which was full of hundreds of homebrewed "utility" functions, including this:

public static string[] GetEmailArray(string emails)
{
    //ArrayList list = new ArrayList (1);
    List<string> list = new List<string>(1);

    if (emails == null)
        return new string[0];

    int len = emails.Length;
    StringBuilder curEmail = new StringBuilder();
    int i = 0;
    while (true)
    {
        bool allDone = false;
        bool doneCur = false;

        if (i >= len)
        {
            allDone = true;
            doneCur = true;
        }
        else
        {
            char ch = emails[i];

            if (ch == ' ' || ch == '\t' || ch == ',' || ch == ';' || ch == ':')
            {
                if (curEmail.Length > 0)
                    doneCur = true;
            }
            else
            {
                curEmail.Append(ch);
            }
        }

        if (doneCur)
        {
            string current = curEmail.ToString().Trim();
            if (current.Length > 0)
            {
                list.Add(current);
                curEmail = new StringBuilder();
            }
        }

        if (allDone)
            break;

        i++;
    }

    for (i = 0; i < len; i++)
    {
        char ch = emails[i];
    }
    //list.Add (emails);

    int num = list.Count;
    string[] arr = new string[num];
    for (i = 0; i < num; i++)
    {
        // arr[i] = (string) list[i];
        arr[i] = list[i];
    }

    return arr;
}

"But..." Trond says, "couldn't you just have easily used:

return emails.Split(' ', '\t', ',', ';', ':');

The developer blinks.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!