Tuesday, July 10, 2007

Learing a New Language

No, some dogs really can't learn new tricks.

But maybe I'm being too harsh. Here's the deal: I was tasked at work with picking up Tcl/Tk as quickly as possible. I think the phrase "Consider it a learning experience" entered into the conversation at least once. (And to be fair, the speaker was laughing at the time, so they knew exactly what they were saying.)

I decided if I'm going to learn something that can build GUIs, it'd be neat to pick something I want a GUI for. So I stuck an ATmega16 in my STK500 board, plugged the programming serial port into my laptop, the device's serial port into my Linux box, and got to coding.

I admit, at the time I got that sheepish, look-over-the-shoulder feeling of doing something wrong, playing with AVRs at work. This is a hobby, right? Keep the twain separate and all that. In the end, though, it took less than an hour to whip something up on the ATmega16 that would drive the LEDs on the STK500 based on what I got in the serial port, and to dump the status of the eight pushbuttons on the STK500 back out. I hoped it wasn't an hour wasted.

Then began the Tcl/Tk experience...

After fumbling around on my own, I did what I do whenever I learn a new language: I take someone else's code that does something close to what I want, and try to figure out how they did it. Except this particular piece of code wasn't commented, and it wasn't the most transparent beast, either. For starters, Tcl/Tk syntax looks nothing like anything else I've ever used. For another, almost everything they did used the canvas command, which is sort of like saying it used the draw stuff command. Flexible? Yes. Simple? No.

In the end I got the push button stuff working. I can push buttons on the STK500 and see my little circular LED things light up or go dark accordingly. I don't quite have the reverse action working yet. Give me time.

In the end I'd love to have a bank of on-screen LEDs for the pushbuttons, checkboxes that drive the LEDs on the STK500, and I'm bound and determined to make some analog gauges to read the ADCs off the ATmega16 as well. That's about as goofy as I can get and still feel good about it in the morning.

As it is I'm still 100% lost. But I'm commenting this other person's code as I learn what it is they did (and why? maybe...) In the end I hope to have something I can read through that'll finally teach me Tcl/Tk. Aside from some raw X11 programming I did in the late 90's, this is the first real GUI I've ever built.

Ok, maybe you can teach an old dog new tricks. Just hurts a lot.

Tom

No comments: