What are you coding?


three year old for scale.

3 Likes

I spent the last 2 days writing an integration test for someone else’s code–the someone else breezed through implementing the cool new thing™ by not writing any tests and then made a ticket about “improving resilience”.

So colleague and me wrote this test. And we had trouble making it repeatable because while most tests have a built-in rollback of DB changes, this thing opens up a separate transaction for something so it was always leaking some extra DB entries. We tried eliminating the extras through the existing DB layer from the software but due to the separate transaction when we tried to delete stuff it wasn’t visible in the other transaction.

We tried and tried and tried and ended up write raw sql (no I lie, it was jpql) to go “directly” to the database to remove the junk entries. And it didn’t work. We tried opening transaction. Committing. Flushing. Nothing worked. And this is a stupid long-running test case… it took forever. We gave up.

I was off from work after lunch. Tonight saw a notification from teams and got curious: Colleague found the issue. Turns out we forgot to actually execute the statements we made.

6 Likes

Me on Thursday:

“Why isn’t this new subcommand working?”
“Because my test window is running the latest release, not the dev branch.”

2 Likes

Too often the error is: the code you are executing is not the code you think you are executing.

6 Likes

I, as oncall, got a ticket that a bunch of continuous build tests had been failing. I looked, and they were timing out. I checked back y to I when they were working, and they were perilously close to timing out then. I guess I have to figure out what is slow. Bother.

4 Likes

So, I mentioned elsewhere that I had set up an automated scanning system but that the flatbed scanner I had purchased for the task (secondhand, from eBay) was defective. I had an old HP OfficeJet 6700 which has a scanner (and a document feeder, which I didn’t have with the other scanner!), but it doesn’t have a button on the device to trigger the scan request on the raspberry pi via scanbd.

So I hacked together an awful Flask web front end to provide the necessary buttons, each running the script with different parameters that mimic the scanbd environment.

4 Likes

That looks like a web UI I’d put together. I’m not allowed to do them, for some reason.

3 Likes

I used Flask to put together a UI for some Raspberry Pi controlled bookshelf lights a while back.

It was similar, functional but not very pretty.

2 Likes

When I rewrite the guts of an algorithm and get a two orders of magnitude speed-up… I stop, and check very carefully.

(But it turns out that abandoning the highly-tweaked permutation generator and writing a much cruder one with a lot of short-cuts to bail out of branches that will never validate is in this case the right thing to do.)

6 Likes

It’s Advent of Code time again, the most magical time of the year!

I just did #1. In PostScript.

The first step is admitting you have a problem.

4 Likes

My mornings just got less productive!

1 Like

I did some math homework in college in postscript, because the most powerful computer I had access to was the laser printer. I have recovered a lot since then.

I did it in python, because I work in it, and am already set up. I expect that I will be tossing what I did today, because it’s not really extensible.
I did think about what the next questions are, but put off using some sensible data structure until then.

2 Likes

Hmm, for me it’s a bit early to speculate on what useful data structures will be. Not every year has an Intcode.

2 Likes

Back in October I had to figure out why one of our in-house programs was printing an incorrect label for one of our products. Turned out that a new customer number had been added, and the program did not have it, so I added it. Or, more appropriately, I swapped what appeared to be an incorrect number with the new one. Issue solved.

Fast forward to today and find out the other number was still in use, and it was now printing the wrong labels. So I added the customer number to the code, but also needed to update multiple lines of code for it to function correctly. Recomplied, reinstalled on the three computers that use the program, done.

Nope, now not only was the wrong template being used, but the data on it was all jumbled. Checked the code again and saw I missed adding it to the section that picks the template. Fixed that and tried again. Looked good.

Then realized the data shown was the defaults for the template, not the correctly pulled data from the database. Go back to the code again and see I missed one more area where the fields are populated from the database. Third time’s the charm, finally working.

And I get to do this again later this month when we add a new customer number who needs this same label template. I probably won’t have Covid then, so I hope to do it correctly in one go when the time comes.

5 Likes

I am glad I didn’t spend time on an elf object.

2 Likes

Can you build some tests for this?

1 Like

I did it in Java because… that’s what I do.

It took me some time to figure out how to do it in 1 single stream though.

(omitting the file operation I needed to read in the input)
    //admittedly I stole the idea of the atomic integer counter from the internet,
    //not that I didn't know it exists... 
    static AtomicInteger current = new AtomicInteger(0);
    private static int dayOne(Stream<String> input)
    {
        return input
            .map( line -> line.isEmpty() ? "skip"+current.incrementAndGet(): current.get()+"-"+line )
            .filter( l -> l.contains( "-" ) )
            .collect(Collectors.toMap( Scratch::splitKey, Scratch::splitValue, Integer::sum ))
            .values().stream().sorted(Comparator.reverseOrder()).limit( 1 ).reduce( 0, Integer::sum );
    }

    private static String splitKey( String line){
        return line.split( "-" )[0];
    }

    private static Integer splitValue( String line){
        return Integer.parseInt( line.split( "-" )[1]);
    }

I was unable to do it without the split hack though and that makes me a sad little elf.

2 Likes

Not done this before so going to give it a go with Python.

Is elegance required or is it OK if I just get the right answer? :joy:

3 Likes

Despite my late high school and early college ambitions, coding is not really my forte, so probably not. :slight_smile:

As the only person with any coding experience at my company (to my knowledge anyway), I am the one tapped to attempt alterations to our in-house programs. The original designer of these left the company a year or so before I started, and a contractor was brought in to update and modify some of them shortly thereafter, and I worked with him for a bit.

So, I middle through as best I can. Luckily this doesn’t happen very often.

image

4 Likes

I gave the link to my other techie friends as well.
And one asked “I did it in XSL, does that count?”
Obviously if you have the solution it counts.

3 Likes