Once upon a time, a client needed Initech to develop a custom tool for them. It would be mildly complex to develop, in terms of developer hours, and in respect of that, the client offered a budget of zero dollars. “But,” they added, “we are looking to do a major upgrade later this year.”

The hint came through loud and clear. Since the development teams charged billable hours, the boss didn’t want to run the project through the usual channels. Besides, there were perfectly good internal development resources, who maintained the internal SharePoint site.

So Terry and Terri, the two SharePoint developers, got their first client-facing project. If you haven’t done any SharePoint development, 90% of it isn’t development at all: it’s about dragging and dropping widgets onto the screen and configuring them correctly. The remaining 10% is a hellscape of absolutely forsaken APIs, infernal coding conventions, and gibbering madness.

Terry and Terri did the boss’s off the books project, the results were handed off to the client, and nobody thought about it until two years later, when, after a rash of bugs and crashes cropped up, someone asked, “Hey, was this ever code reviewed?”

Which is how this code ended up on Erica’s computer.

The goal of this block of code is to sanitize a string. The string contains double quotes, which need to be removed. There also might be a space, in which case only the content before the space should be taken.

Terry and Terri produced this:

str = (str.Remove(str.LastIndexOf("\"")) + " \"");
if (str.Contains(" ") )
{
    var s = str.Remove(str.IndexOf(" ")).Trim("\"");
}

This code removes the last ", then adds a space… followed by a double quote. Once we definitely have a space in the string, we check to see if the string contains a space, and if it does, we remove the first space in the string, and then trim off the double quotes.

When Erica asked the Terri(y)s how this happened, they explained a little bit about their development process: when they encountered an error, they added more code until the error went away.

Erica raised this issue up with her boss. The boss, to Erica’s eternal joy, said, “Great, this sounds like a training opportunity. Teach Terry and Terri how to improve this code, and they’ll be better developers.”

Now, Erica wasn’t exactly skilled in training, but neither Terri nor Terry were skilled in development, so this was doomed to failure from the start. Erica spent three days trying to explain to the Terry(i)s that this code was wrong, and needed to be changed. Terry replied, “I’ve looked at it, and I think this code is ingenious. We shouldn’t change it, because that might break something.”

In the end, Erica couldn’t provide the training that the Terr(i)ys needed, but she certainly had some more suggestions for some other changes- staffing changes.

[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!