Derrick Pallas

Early Termination

by in CodeSOD on

Once, I asked a coworker for a feature request. His service was outputting hashes and I wanted the original strings. His reply was that if I had an algorithm to reverse a hash --- all that this service stored and obviously impossible --- he'd implement my feature. My suggestion was that he record an input-to-hash mapping and just reverse that. The feature was checked in that day; perspective makes all the difference. My next feature request was that he set up a signal handler to catch signal nine, as he had attached cleanup routines to several other signals. I guess he spent the rest of the day trying to figure out why it wasn't working.


And I guess that's the point: for many things there is an obvious solution, for some things there is no solution, and wisdom is knowing the difference. The problem is second-guessing things that cannot occur, especially when you guess wrong. One of our field agents, Paul, recently had a run in with murderous #9; he writes,

'We once bought some code from a large company who shall remain nameless. Security was the big issue, so a programmer came up with the not-so-bright idea of how to be sure that a small utility program would really exit and not somehow keep running.

Splitting Headache

by in CodeSOD on

When it comes to string manipulation, it is not uncommon to want to split a single string into multiple strings based on a delimiter. Many languages provide split functionality outright. Even in C, it's fairly easy to roll your own --- assuming you don't like strtok_r --- with functions like strchr or strpbrk.

Jake says that, in Java, this was not the case until 1.4, which is the same thing the documentation says. Apparently one of the developers with whom he works still does not realize this. The following function was developed recently and is still being used in new code.


Buzz, Cell Phone, Buzz

by in CodeSOD on

Mobile communications is a complicated but lucrative business. With all the buzz surrounding (and created by) cell phones, that's not surprising. And they're not just for calls any more! The new big thing is interacting with web pages and other applications via SMS.


What's SMS? Who knows, but it's an acronym so that means it's probably great. At least that's what Jared's company thought, which is probably why they were in a mad scramble to interface their web service with every cellphone on every network, ever. The problem? No one knew anything about how SMS worked.



Double Take

by in CodeSOD on

This is the story of two Daves. At first, they may appear to be from completely different worlds. One does client-side web development, one server-side web services. On further reflection, however, they have quite a bit in common.


For one, they both ended up together in this article. That sounds like a match made! With that in mind, Alpha Dave has something on his chest. Also, he needs to get it off.



Deterministic Programming

by in CodeSOD on

There is a lot of uncertainty in the life of every developer. How will this section of code interact with that section? What if the network goes down? What if a gamma ray flips that bit? What's mom making for dinner? Does radon have a smell?


In fact, a large part of computer science is the study of how to eliminate uncertainty. At the top, there are formalisms like the pi-calculus and abstractions like CSP. Sometimes simple state diagrams can be a godsend. And even if you've never seen any of those, there is still room to do your part.



That'll Show the Grader

by in CodeSOD on

When I was grading for the Software Engineering course, I saw some pretty awful things. Most of the students were actually alright programmers; in fact some were pretty good. The trouble was that neither the really good ones nor the really bad ones came to lecture, so it was impossible to tell who the bad ones were until after it was too late to help them. Mostly, this was because we only began grading the term project --- interactively, as milestones --- late in the term.


Most groups still ended up getting the application to run but there were always one or two students that couldn't explain the system they were supposed to have helped design. During these evaluations, there were three types of teammates. The first was the person that couldn't sit still, wanting to pick up the slack. The second was the person that could only sit still because they, though fairly competent, knew that the application didn't really do what it was supposed to. And then there were the teammates that took sadistic pleasure in watching their randomly assigned partner suffer.



Eliminating Shady Characters

by in CodeSOD on

"These characters are real troublemakers," writes Cody. "You know the guys. Hair slicked back, boots, leather jackets. Or else, pants hanging down to their knees, pagers going off. Wouldn't it be great if we could just get rid of them? Wouldn't that make life a whole lot easier?"


One of the developers he works with thought so too. These punks were messing with the system, pretending to be foreigners. That's when the coworker took the law into his own hands and decided to "get ridoff" them himself.


/**
 * This function is called from jsp to get ridoff some
 * of the special characters
 */
public static String removeSpecialChars(String a_sValue)
{
    if (a_sValue != null)
    {
        a_sValue = a_sValue.replace('\'', ' ');
        a_sValue = a_sValue.replace('\"', ' ');
        a_sValue = a_sValue.replace('&', ' ');
    }

    return a_sValue;
}


The Case for Switch

by in CodeSOD on

Little more than a structured goto with a nicer getout, every C programmer knows (and many love) the switch statement. Even if you don't love it, there are obvious uses that produce cleaner code than strings of else-ifs and help prevent many simple kinds of errors.


Take for instance the following code, for which Gulliver writes in asking, "how many times do you have to check a condition?"


void ReplaceCommas (char *buffer)
    {
    int i,j;
    j=strlen(buffer);
    for (i=0; i < j; i++)
        {
        if (buffer[i]==',')
            {
            if (buffer[i]==',') buffer[i]='.';
            }
        if (buffer[i]==',')
            {
            if (buffer[i]=='"') buffer[i]='\'';
            }
        }
    return;
    }



Archives