Friday, May 23, 2008

Infinite Loops

Recursive blanket flower by Flickr user gadl, whose work totally rocks. (I used another gadl image in an earlier post.) Used under a Creative Commons license.

Warning to actual computer experts: The following is a mix of muddled memories that both oversimplify and distort the way programming works just so I can make a silly metaphorical point about my children at the end. Don't say you weren't warned.

So, back in the early to mid-1980s, when I was going to college in the Silicon Valley, pretty much everyone took a class in computer programming no matter how talented or clueless we were about computers. It was just what you did. The language we learned was Pascal, and though I've hardly ever heard about it since then, it's still considered a good starter language for picking up the basics of programming (or so says Wikipedia).

Being exceptionally clueless about my future, I took not one but two programming classes. About all that stuck is an ability to create nifty "if" statements in Excel spreadsheets that automatically convert a numerical grade into a letter grade and vice versa.

Conceptually, two ideas are still with me: recursion and infinite loops. They somehow got hard-wired through marathon late-night programming sessions, which were inescapable because time on the mainframe was strictly limited except between 2 and 6 a.m. (The mainframe! It took up a room the size of my house.)

Recursion is just a mindblowingly crazy weird idea: stuff nested inside of other stuff, like a programming version of Russian matryoshka dolls. There are more formal - and no doubt better - definitions of recursion, but the cat below will give you the basic idea. (Unless, of course, you're an actual computer person, in which case you're probably scoffing at me, as you should. But hey, you were warned back in the first paragraph.)

Recursive cat by Flickr user raincrystal, used under a Creative Commons license.

Recursion is one of those things that makes a lot more sense right after a Grateful Dead show. As it happens, when my recursive program was due in the winter of 1985, I spent the evening at a show in Oakland (it must have been part of the Chinese New Year festivities) and then came home and started the program around midnight. It was done before the sun came up and worked perfectly on the first try.

The other concept that's endured for me is the infinite loop. Programs use loops to perform an action repeatedly. They normally stop obediently when the specified task is finished or a desired condition is achieved. For instance, if you search Google for Kittywampus, it searches until it's got the results and no longer. (I have no clue what sort of algorithm Google uses or if you can even call it a loop, but the point is, the search is finite.)

An infinite loop is one run amok. It doesn't stop tidily but keeps on going, usually because the programmer screwed up somehow. It doesn't know when it's time to stop. (One way it differs from recursion is that a recursive program or function knows when enough is enough.) I created at least one of these, too, although that was (obviously!) not part of any assignment.

These days, I have one big infinite loop in my life, and I'm mostly at a loss about how to stop it. That loop is a never-ending squabble function.

My two boys - who can be so sweet, smart, and empathetic - spent the winter squabbling ferociously. It starts predictably in the morning with the Tiger deliberately making annoying noises at the breakfast table (aka the "breskit table") and the Bear using his bossiest voice to order him to stop. It ends only after they've argued over whose turn it is for a piggyback ride from their dad up the stairs at bedtime.

The quarreling escalates massively whenever they have friends over, particularly when the Bear has a playdate and the Tiger wants to join in. The Bear wants to play big kid stuff; the Tiger wants to be part of it, even if it's only by crashing the party and trying to plant sloppy kisses on all the other kids. I understand that they both have legitimate desires and needs, but so far compromise only leaves both pissed off.

I'm actually not beating myself up about this too much. I think both his dad and I try to be fair; we try not to intervene constantly, but we also try to teach them that compromise is the only alternative to misery. (Of course, I'm grateful for any words of wisdom from anyone who's handled this more successfully!)

The proof that this is an infinite loop came a couple months ago when I told the Bear to pick up some underwear he'd left lying on the floor. He balked. The Tiger said, "I want to pick up the underwayer!" The Bear said, "No, I will!" and a tug-of-war ensued - over underwear and who would get to pick it up!

For an infinite loop, the only thing I know to do is reboot. But with kids, it's not at all clear where the on/off switch is located. I'd RTFM, if only I had one.

What's working right now: spring! Now that the kids can be outdoors without suffering frostbite, I'm mercilessly kicking them out into the yard. Yep, the Tiger tried launching a kissing attack outdoors, too, but on the whole they've been a lot kinder to each other. And that makes me even happier than the flowers bursting out.

Recursive stained glass by Flickr user gadl, just because I love it. Used under a Creative Commons license.

4 comments:

Sugarmag said...

My older one is a girl and year younger than the Bear, but what you described is my life, Sungold. I want to pick up the underwear! No, I do!

Sungold said...

Oh gosh, I so love company in my misery! This was *dirty* underwear, mind you!

Some of my friends claim that a boy and a girl would get along more easily, but you've got one of each - so much for that theory.

John Pine said...

They are learning justice and dispute resolution. Montessori talks about 'sensitive periods' in which something vital has to be learnt before it is too late.

If they quarrel about e.g. who will have the blue plate, try putting the blue plate on top of the cupboard until they have agreed about who should have it. All sorts of plea bargaining etc. will probably start.

Who will pick up dirty underwear? That just shows how bizarre children can be in inventing court cases to practise over!

Sungold said...

John, I do often confiscate items that are in dispute - in fact, I think I took away the controversial underwear, too! :-)

It's nice to get the long view. I do know that this is all part of a learning process. And it's amazing how much it teaches me about myself, including my own limits. It's humbling, each and every day.