obligatory obscure reference


self-deprecating yet still self-promotional witty comment

2009/08/08

Can We Teach Debugging?

Filed under: Arduino,Hacking — jet @ 12:01

[thx to Tom Igoe for making me write all this down]

Question: Can we teach people how to debug? We often talk about “the art of debugging”, but is it really an art? Is it a science? A mixture of both?

I’ve never given thought to explicitly teaching a unit on debugging, it’s always something that gets covered along the way while teaching coding and physical computing. Which isn’t surprising, I don’t remember anyone teaching any sort of debugging in any of my CS classes or ever thinking of it as an academic subject. It was mostly treated as a practical thing that we’d pick up after we got work. You get your first few coding jobs, you have bugs to fix, and someone senior (usually) comes by and teaches you what they know about finding bugs in software.

However, I think that where I really learned how to debug wasn’t while writing software, it was while working on cars and motorcycles. When you’re faced with a motor that won’t start or a strange noise or an intermittent failure in some part of the electrics, you have a problem space much bigger than you can see all at once. You have to break the problem down, rule out areas that can’t obviously be at fault, and try and focus on the areas where the problem might lie. There’s an iterative process of selecting smaller and smaller domains until you get to the point you can start asking questions that are simple enough to be easily answered. “Why won’t the car start?” can’t be answered until you’ve answered all the little questions, like “is the battery fully charged?” or “is the fuel pump sending fuel to the carbs?” or “are the spark plugs firing?”. More often than not, answering those questions simply leads to even more big questions that have to be broken down again, “ok, why isn’t power getting from the battery to the spark plugs?”

Another issue is that in the physical world, you don’t have x-ray vision (debuggers) or the ability to replicate the problem over and over without causing physical damage (“let’s add some printf’s and run it again”). You have to learn to break the problem down into tests that won’t damage the engine or make the problem worse. You also can’t magically make most of the car go away with #ifdef’s in order to isolate the problem, you have to physically connect and disconnect various things both for safety reasons and so that you can perform proper tests. (Always remove the ground strap from the negative pole of the battery. No, really. Trust me on this.)

When unit testing started gaining in popularity in the software dev world it made perfect sense to me. This is the way I fix a vehicle — break the problem down into increasingly smaller chunks, isolating unrelated systems from one another, to the point that I can “Has the flayrod gone askew on treadle, yes or no?” instead of being stuck at “there’s a problem at the mill”. Granted, we use these tests to prevent bugs in code under development, but adding them to an existing code base often reveals all sorts of, “oh, so that’s why it makes that odd noise on Tuesdays after lunch” bugs that were never worth tracking down. The problem with unit testing, however, is that you’re usually adding it from the bottom up while you’re actively focused on the task of software development. You’re almost ruling out the need for debugging later by doing extensive testing now, or you’re adding it to an existing code base to “increase stability,” as they say. (In other words, there are all sorts of mildly annoying bugs we can’t find easily, so let’s just add unit tests and hope that fixes things.)

My gut feeling is that there’s a pattern involved in debugging both hardware and software problems, and that the pattern is similar to other patterns we use in hacking and design. I believe “my car won’t start” and “my LED won’t light” can be solved using similar methodologies to generate domain-specific questions. Each domain requires its own set of knowledge and specialized tools, but I think the process for fixing each problem is similar.

So how do we teach debugging? I think we start by teaching the good ol’ scientific method, translated to computational space:

  1. Have you solved this problem before? If so, repeat your previous investigation to see if it’s happened again.
  2. Define questions that you can answer with simple tests.
  3. Perform tests and collect data
  4. Analyze results.
  5. Repeat 1-4 until problem is solved.

Ok, granted, that seems pretty obvious, but it took us humans a really long time to sort that out and write it down. I suspect most of us couldn’t recite the scientific method off the top of our heads, especially if we didn’t study science in high school or college.

Using these steps also requires a certain amount of domain specific knowledge and ability to choose and use the appropriate tools. If I don’t know ground from positive and that current can only flow through an LED one way, I’m not going to get very far figuring out why my LED won’t turn on because I’ll never be able to ask the correct questions.

In theory, what we’re teaching when we teach computing is the necessary domain specific knowledge and tools, so the student should be able to debug simple problems in their own work. What I’m suggesting is that we also hammer on the above methodology any time a student shows up saying, “my LED won’t turn on”. Make the student break the problem down, generate the questions, then show the student how to answer those questions if they’re unable to do so on their own. If the student can’t ask the right questions, then there’s a bigger problem: the student doesn’t have the domain specific knowledge to turn the LED on in the first place. If the student can ask, “is there power to the LED” then you can show them how to use a multimeter to answer that question. But if they’re still unclear on polarity, then they’ve got a bigger problem.

I think we can teach debugging, even though we weren’t taught debugging when we were learning. Not only can we, I think we do students a disservice if we don’t teach debugging as a core competency.


Footnotes: “Kit-building isn’t learning” and “It’s not my fault that Windows sucks”.

There are at least two exceptions to the above.

1) Building a kit isn’t the same as studying and learning a subject. Knowing only how to solder and read English, one can put together kits ranging from a simple Adafruit Arduino kit to a complex synthesizer from PAiA. But unless the builder does research into why the kit is put together the way it is, they haven’t learned much, if anything, about what they’ve built. As a result if there is a problem, whether it is in the instructions, the components, or their assembly, they’re going to find it very difficult to ask the right questions that will let them debug the problem. (I’ve assembled kits from both outfits and they both provide excellent kit-building instructions.)

2) Windows sucks. Ok, all computers suck, but Microsoft has spent decades innovating new and wonderful ways for Windows to suck, so I’m picking on them. There comes a point in debugging a hardware or software problem where the problem is out of operational scope. Maybe “my LED won’t turn on” because there’s a subtle bug in the USB driver between the IDE and the breadboard. The student will probably never have the domain specific knowledge needed to start asking questions about the USB driver, and odds are the instructor won’t either. Sadly, even the person who developed the driver or tool or OS can’t formulate the right questions either, this is why the final step in many troubleshooting guides is, “reinstall the drivers and then the operating system”.

[tags]debugging, pedagogy[/tags]

2009/06/29

ARToolkit camera calibration file for ecamm iMage

Filed under: Hacking — jet @ 22:55

I’ve been happy using the ecamm iMage with my Macs for Processing, so I decided to go ahead and use it for ARToolkit as well.

Before I ran the two-stage calibration, it barely worked. I did the two-stage using only cardboard boxes and rulers to prop things up and keep things square, and the resulting calibration file is very usable.

I’m posting rev 1 of my calibration file, let me know how it works for you.

[tags]artoolkit, ecamm, image[/tags]

2009/06/15

What Pittsburgh can learn from Japan

Filed under: , The Future Of,Pittsburgh — jet @ 15:56

I’m just now back from spending two weeks in Japan, almost exclusively in Tokyo. While the two cities are obviously very different culturally, I noticed some similarities between the two and was intrigued by how Tokyo’s residents benefit from things that Pittsburghers see as problems.

First question: How big do you think Tokyo is? Huge, right? 12 million people?

Wrong. Tokyo is (was) actually pretty small. It was a single town in the middle of the Tokyo Prefecture, which covers what we would call the greater Tokyo metropolitan area. There are actually 23 wards (think boroughs) in Tokyo, each that collects its own taxes and has its own local government. If you live in Shibuya you pay different taxes than if you live in Roppongi, but for those of us who don’t live there, we’d never know (or care) about such details. We see a huge city with consistent signage, the Tokyo Metro Police helping tourists, Tokyo Fire Department trucks being washed/polished, and the wonderful collection of decorated sewer and storm drain covers of the public services.

So how big is Pittsburgh? Is it a little town or is it a region? I live two towns away from Pittsburgh, yet my mailing address is still “Pittsburgh, PA”. A friend of mine in California told me he was from Pittsburgh, it turns out he’s from Murraysville.   

Now, how many police departments do we have in “Pittsburgh”? How many fire departments? How many road maintenance organizations?

Could the Borough of Forest Hills, Swissvale, and WIlkinsburg continue to retain what identity they have while sharing a police force with Pittsburgh and one another? Would “Pittsburgh” benefit from having unified police and fire departments that shared frequencies, training, and equipment?

I’m not talking about consolidating cities, I’m talking about sharing resources that are common across adjoining towns and communities. Pittsburgh already has several “zones” for its police department, would adding another zone (or few) be cheaper than operating multiple, tiny police departments with duplicated services?

[tags]pittsburgh, tokyo[/tags]

2009/05/25

slowly catching up on the blog thing

Filed under: Metalworking — jet @ 21:31

Finally finished my MS Design degree and now have time to write for people other than professors and whatnot. I’ve got a bunch of half-finished posts to clean up, but I’m too busy doing metalworking stuff in the studio to write very much.

The current project is installing a 60G compressor, which also means bolting it to the floor, running hard line and adding a 220V circuit. I hemmed and hawed about which mini compressor to get, then just said “screw it” and went with a big 60G unit. More than enough PSI and CFM for anything I’ll do in my “one-car” sized studio, and when I get real studio space, I’ll move it there.

Still debating what my first air tool should be, however. I’m thinking a die grinder or a sheet-metal nibbler.

[tags]metalwork[/tags]

2009/04/02

Arduino MEGA is made of win

Filed under: Arduino,Hacking — jet @ 13:34

and it’s rather large.

Something that has continually bugged me about the various flavors of Arduino is the number of pins that there are not 8 of. As in, 5 analog pins or 6 PWM pins or whatever. I end up adding multiplexors so I can drive 8 PWM outputs or read 8 sensors or what-have-you.

Arduino MEGA fixes all my problems, at the cost of size and a few extra $$$:

PWM: 14 pins, I’ll try not to complain about it not being 16

Analog Input: 16 pins

Thanks to all the extra I/O, I was able to ditch a specialized, $25 PWM controller and some support hardware and move my entire project from a pc board to an Arduino MEGA shield.

[tags]arduino mega[/tags]

2009/02/21

“Broken Windows” theory of crime has merit

Filed under: , The Future Of,Pittsburgh,Politics — jet @ 17:18

Perhaps folks in local government can learn something from the success in Boston?

“[…]

Researchers, working with police, identified 34 crime hot spots. In half of them, authorities set to work – clearing trash from the sidewalks, fixing street lights, and sending loiterers scurrying. Abandoned buildings were secured, businesses forced to meet code, and more arrests made for misdemeanors. Mental health services and homeless aid referrals expanded.

In the remaining hot spots, normal policing and services continued.

Then researchers from Harvard and Suffolk University sat back and watched, meticulously recording criminal incidents in each of the hot spots.

The results, just now circulating in law enforcement circles, are striking: A 20 percent plunge in calls to police from the parts of town that received extra attention. It is seen as strong scientific evidence that the long-debated “bro ken windows” theory really works – that disorderly conditions breed bad behavior, and that fixing them can help prevent crime.

[…]

[tags]crime, pittsburgh[/tags]

2009/02/02

Pittsburgh’s “Culture of Complacency”

Filed under: , The Future Of,Food and Restaurants,Pittsburgh — jet @ 19:35

On the way home tonight I stopped at a PCLB store (state owned liquor and wine but no beer store) to pick up a bottle of cheap sake. Good sake is hard to find here, but at least PLCB stocks Sho Chiku Bai Nigori, a fine table/drinking nigori. The PLCB I stopped at has a history of having “something other than gekkikan”, so I was checking out the good stuff and considering maybe trying a new ginjo or two.

Then I noticed bottles of Sho Chiku Bai Organic Nama Nigori on the shelf.

Yeah, you read that right. “…Nama Nigori on the shelf”. I don’t know that non-refrigerated sake is bad for you, but it’s probably going to taste pretty foul.

What happened next is a wonderful example of what I think of as a culture of complacency.

Me: Excuse me, but there’s a problem with some of your stock.

Manager: What?

Me: This sake. It’s nama sake, it’s unpasteurized, and if it’s not refrigerated it will go bad. It’s probably not safe to drink either, I don’t think spoiled sake is something I’d want to drink.

Manager (showing no interest in looking at the bottle): They ship me stuff, I put it where they tell me.

Me: Right, but they apparently didn’t tell you this needs to go in the fridge.   

Manager (still no interest in looking at the bottle): Look, I told you, they ship me stuff, I put it where they tell me.

Me: Ok, but it even says on the bottle to “keep refrigerated”. If it’s gone bad, or if it’s a health risk, you aren’t going to at least take it off the shelf?

Manager: Nobody’s returned any of it yet.

Me: Well, you just started carrying this. I’ve been living here 3 years, this is the first time I’ve seen nama anywhere in a state store.

Manager: I’m telling you, they ship me stuff, I put it where they tell me. You don’t have to buy it if you don’t want it.

And yes, I’m notifying the PLCB and ACHD including store and date/time of visit…

I’d like to think that if I went to a manager/owner of a privately owned store and said, “hey, one of your products is definitely gone off and might be bad for someone to drink” that their response wouldn’t be “so?”

[tags]complacency, pittsburgh, plcb, sake[/tags]

2009/01/11

Mac OSX + VMware + VX-7R Commander

Filed under: Amateur Radio — jet @ 20:29

If you’re into Amateur Radio and a *nix nerd, you probably know firsthand how little support there is *nix/*bsd/OSX. There’s a really great freeware program for managing a VX-7R, but it’s only on wintel.

Turns out that isn’t a problem if you have VMware and XP Pro. I wouldn’t have bought those just to support a radio, but the only PC app I “need” is SolidWorks. Everything else I do in darwin/bsd or linux. I really can’t justify carrying around two laptops all the time, and I’d have bought XP and SolidWorks if I did have a PC…

Here’s what I did to get VX-7R Commander working on my MacBook:

1) Use an IOGear QUC-232A cable as a USB<->serial adapter to the VX-7R adapter cable.

3) In XPPro under VMWare, download the drivers from IOGear’s site and install them. They installed as COM3 on my system by default.

4) Launch Commander, set it to use COM3, and I was able to download/upload with no problems.

[tags]OSX, VX-7R[/tags]

2009/01/08

Sanguino: First Impressions

Filed under: Arduino,Hacking — jet @ 18:59

The reprap people have a new arduino-like out, the Sanguino. It uses the Atmel atmega644p, so it has 4x the memory, 14 more i/o pins, and JTAG support.

I ordered a couple of kits and soldered them up. Instructions are easy to follow, both for soldering up the board and for modifying Arduino to support the new chip. However, I ran into two problems right off the start, one of which would have probably stymied someone without any arduino/microcontroller experience.

1) No bootloader was installed on the Atmel. This is not the end of the world if you have a bootloader lying around. We had one in studio, but I can’t find it and everyone else is out of country/town. I took this as a sign that I should have my own, so I ordered a couple of USBtinyISP‘s from Limor (always buy two of anything you rely upon), soldered them up, and bootloaded the Sanguino. I wrote a simple sketch that blinks the debug LED, pushed it to the Sanguino and yea, everything works now!

Now, to try replacing the Arduino nano or mini on one of my project boards.   

2) Oh. How cute. It won’t work on a breadboard. The spacing on the Sanguino pins is so wide that when it’s plugged into the center of ye olde standard breadboard, you can’t access one side of the Sanguino’s pins. That is, if you put one side of the Sanguino in column b so that you can use column a, the other side is in column j, not in column i. Looking at the board layout, I think this could have been completely avoided by moving the pins in a “row” on each side, and putting the labels for the pins inbetween the pins ala the Nano.

Yuck. I guess I’ll have to get clever if I want to use this with my existing projects.

[tags]arduino, sanguino[/tags]

2009/01/07

Come Visit Us at Frostburn 2009

Filed under: Random and Pleasing — jet @ 02:06

Frostburn is a “regional burn”, where local Burning Man types get together for a Burning Man style event. Frostburn is one of the few, if only, regional burns where survival is as much of an issue as it is in Black Rock City. Last year, temperatures were in the teens to the 20s and keeping warm was as important as keeping hydrated is on the playa.

We’ll be there again this year, with another Iced Tea event featuring the newly resurrected Colordome.

Join us, won’t you? I promise it will be more fun than being stuck in a lift line in some random crappy sky resort.

[tags]burning man, frostburn, geodesic domes[/tags]

« Previous PageNext Page »

Powered by WordPress