Remy Porter

Computers were a mistake, which is why I'm trying to shoot them into space. Editor-in-Chief for TDWTF.

Mar 2017

Prepared for the Real World

by in CodeSOD on

Usul is taking a college course on Java programming, and it’s doing an excellent job preparing him for the real world. Already, he’s been forced to cope with someone who knows one true fact and has run off to apply it in the dumbest way possible. This would be his professor.

Our true fact is this: A Java PreparedStament object, used for running database queries, should be closed after use. This returns its connection to the pool and frees any resources the statement was using. You should do this, and you should do it as soon as you’re done with your connection.


The Refactoring

by in CodeSOD on

I have certain mantras that I use to guide my programming. They generally revolve around this theme: "Thinking is hard, and I'm not very good at it; every block of code should be simple and obvious, because if it makes me think, I'll probably screw it up and break something." It's a good rule for me, and a good general guideline, but it's a little vague to implement as a policy.

Erika’s company wanted to implement this idea as a policy, so they set a limit on how many lines could be in a single method. The thinking was that if each method was short- say, under 100 lines- it would automatically be simple(r), right?


Dictionary Definition of a Loop

by in CodeSOD on

Ah, the grand old Dictionary/Map structure. It’s so useful, languages like Python secretly implement most of their objects using it, and JavaScript objects imitate it. One of its powers is that it allows you to create a sparse array, indexed by any data type you want to index it by.

Catherine’s cow-orker certainly thought this was pretty great, so they went ahead on and used the Dictionary to map interest rates to years. Years, for this application, were not tracked as actual years, but relative to an agreed upon “year zero”- the first year of the company’s operation. There was a new annual interest rate tracked for each year since.


Countup Timer

by in CodeSOD on

Dan has inherited a pile of Objective-C. That’s not the WTF. The previous developer had some… creative problem solving techniques.

For example, he needed to show a splash screen, and after three seconds, make it vanish. You might be thinking to yourself, “So I set a timer for 3000 milliseconds, and then close the splash screen, right?”


Episode 4: Anarchy for Sale

by in Software on the Rocks on

Thanks to a combination of illnesses, travel, timezones, and the other horrors of the modern world, we took a week off. If Angular can skip version 3, we can skip episode 3. Welcome to Episode 4 of Software on the Rocks, brought to you by Atalasoft.

In today’s episode, we are joined by TDWTF author Jane Bailey. We talk about the process of writing, the nature of programming, and “programmer anarchy”.


Still Empty

by in CodeSOD on

A few months ago, Hannes shared with us some recycled code. In that installment, we learned that one of his team mates has… issues with strings. And naming things. And basic language features.

These issues continue.


The Installer Configuration

by in Representative Line on

John N supports a C# project that, on first run, needs to initialize a database. It pulls that data from a dbInstallFilePath, controlled by the application .config file. This brings us to our representative line:

    <add key="dbInstallDbFilePath" value="C:\TestData\" />

Misdirected Emails

by in Feature Articles on

John C was a vigilant protector of justice, a dark guardian of a public who didn’t even know he existed, striking fear into the hearts of criminals. Specifically, he did IT support for the local police department. It wasn’t a great job. Their infrastructure was ancient, underfunded, and under-supported. He was expected to provide just as much support for the department’s website as well as their radio system. The customers were a “special” brand of ignorant, and often pretty angry about it. The department provided service 24/7, which meant John was expected to be available at weird hours, and not even for emergencies. Many of his customers only worked night shifts, and he had to support them.

At around 3AM, John caught a ticket, entered in by one of the secretarial staff. “Officer Bishop reports her email is broke”. With that cornucopia of information, he called Officer Bishop.

Newman, the mail-carrier character from Seinfeld, in uniform

WriteTenMemoryLocations

by in CodeSOD on

Let’s say you needed to initialize a buffer to be 260 bytes long, and they all should be 255. Now, you’re using a high-level language, like C#, to talk to a legacy device, so you might have to jump through some hoops to deal with the device API, but how hard could it be? A better question might be, “how hard can you make it?”

There’s an old saying: “fast, good, or cheap: pick two”. Massimo’s employer doesn’t want to be greedy, so they consistently pick one: cheap, which means they get code like this:


Cloning Date

by in CodeSOD on

We get a lot of bad date code samples. Since we all learned to read a calendar in elementary school, everyone assumes they actually understand how dates work, and then tries to codify that knowledge in code. Bad date code is like entry level awfulness, and it takes a lot to surprise me when I see bad date handling code. Mike R knows how to do it, though. He found this code buried in a 30+ file commit, with the helpful commit message, “asdf;”:

public class DateUtil {
    private DateUtil() {
    }
    public static Date setDate(Date date){
        if (date == null) {
            return null;
        }
        return new Date(date.getTime());
    }
    public static Date getDate(Date date){
        if (date == null) {
            return null;
        }
        return new Date(date.getTime());
    }
}


public class DateUtilUnitTest {

    @Test
    public void testSetDate() throws Exception {
        Date date = new Date();
        Date result = DateUtil.setDate(date);
        assertThat(date,is(result));
    }

    @Test
    public void testSetsNullDate() throws Exception {
        Date date = null;
        Date result = DateUtil.setDate(date);
        assertThat(date,is(result));
    }

    @Test
    public void testGetDate() throws Exception {
        Date date = new Date();
        Date result = DateUtil.getDate(date);
        assertThat(date,is(result));
    }

    @Test
    public void testGetsNullDate() throws Exception {
        Date date = null;
        Date result = DateUtil.getDate(date);
        assertThat(date,is(result));
    }
}