Signs I should stick to knitting rather than programming

This incident made me think about debugging more broadly.

A couple of weeks ago I was sent some knitting yarn as a gift. The person sending it mentioned that there’s instructions inside the package for making a basic scarf. As you can imagine even if you don’t knit, a scarf is one of the simplest things you can make and generally involves knitting a long strip of a uniform width until the scarf is long enough.

Now, I’m not an instructions enthusiast at the best of times (see also: flat pack furniture) but step by step on a scarf is too far. It turns out though that the instructions are aimed at very basic beginners and show how to actually create the stitches and so on, so it seems reasonable. So it doesn’t just say “cast on 25 or whatever makes it the right width and then knit until it’s long enough”.

Friend who was with me immediately drew out a spoof flow chart basically consisting of: Knit – Is scarf long enough? – Yes – stop or No – arrow back to Knit. (I’m not quite geeky patient enough to actually replicate the flow chart in Dia though I did consider it!) The background is flow chart, system and process obsessed people who impose overly formal systems and structures on even basic things (something friend and I have both had run ins with in the past).

I should say that although I don’t “do” detail, flow diagrams and step by step etc, I can never get enough spoof flow charts and KPIs (‘Key Performance Indicators’.. charts of metrics basically and even the word metrics is a bit dubious), especially those created by me.

I had simultaneously come up with a pseudocode BASIC program on the whiteboard:

10 knit a bit
20 if knitting = long enough then goto 10
run

Of course, most anyone (programmer or not) could very easily spot what’s wrong with this ‘algorithm’. When my friend pointed quizzically to the ‘=’ I assumed the equals wasn’t legible and made it clearer! Eventually I spotted the error and “corrected” the = sign to !=. Friend (who doesn’t have a Diploma in Computing and isn’t currently doing an independent computing research project…) corrected it to ‘<’. In fairness to me I was simultaneously on the phone and had had a couple of drinks but that’s no excuse!

In general we only ever see what we expect to see rather than what’s really there and that’s one of the reasons it’s not normally a good idea to do one’s own debugging for logic errors (syntax errors, different story, they are generally easy to debug). Anyone who’s been programming for a while has their own ‘pet’ errors they always make and if they can’t be stopped (obviously preferable) then at least be aware of them as a possible/probable source of bugs.

My own pet error is in languages such as Java, using = when I mean ==, specifically in while loops and if statements. The assignment operator = actually assigns a value to something (and returns true) whereas == tests if it’s equal as a true or false value (as of course you know if you are a programmer yourself).

So for example where I put something like:

if (catCount == mouseCount)
{ do something… }

this has a very different meaning to:

if (catCount = mouseCount)
{ do something… }

The second one is actually valid Java syntax (obviously the “do something” part would have to be replaced with some Java code!) but would result in a ‘bug’ where the progam will “do something” regardless of whether catCount is the same as mouseCount or not.

Most bugs aren’t obscure or existentially based.

The software development IDEs have compiler features that check for syntax errors and uninitialised variables etc but it would be good to have something that helps check for logic errors like the one above (I don’t know if anything like this is available). All languages and systems probably have easily made errors like this (like in SQL where you can “update table set fieldName = null” and apply a change to every record in the table easily and mistakenly).

The moral of the discussion with said friend was that if that algorithm somehow made it into an industrial knitting machine, the machine operators would just have a machine that ‘inexplicably’ doesn’t knit by itself as it’s supposed to, you have to keep pressing the KNIT button (or whatever) to do it in bits until it reaches a certain length at which point the machine zooms off by itself and can’t be stopped other than by turning it off.

The moral of this one is to be aware of your own normal errors and don’t assume you’re above them!

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*


These ads help pay for the hosting costs...

Contact

Comments are enabled (but moderated) or you can email privately - remove the spaces from grainy-squares @ thetorturegarden.net

Image credits

Thanks to Webtreats for the wood image used under Creative Commons
Thanks to Editor B for the gecko image used under Creative Commons

Author photo

Yahoo! Avatars