Monday, July 21, 2008

Autobiographical Landmark: Mod

I've been programming computers since a notoriously terrible teacher introduced me to BASIC on an Apple II computer some time in the mists of the 1980s, but only in the last few days have I finally found a reason to use a modulo operation, which is rendered as mod in quite a few programming languages.

What context, you ask? I needed to identify and discard each of the second and third instances of an indefinitely repeating three-thingy pattern, and used mod to find them. Mod returns the remainder, so every thingy in the numbered series such that thingy mod 3 <> 1 turned out to be one of the droids I was looking for.

Neat.

I can't remember the terrible teacher's name, just the frilly white shirts she'd wear -- something like the shirt from the "The Puffy Shirt" episode of Seinfeld -- and the 1980s eyeglasses with gigantic frames that dwarfed her bony face. Alas, she was a victim of the times just as we were the victims of her impatient, incompetent teaching.

She taught me nothing of mod. And for my part, I have given you nothing here but a cosmically boring window onto my life and further confirmation that you never, ever want to do computer programming.

4 comments:

George Junior said...

The Apple II. That takes me back.

The first desktop machine I got my hands on was a Commodore Pet - with 8KB of RAM. Before the PET came along I was using punch cards!

Dale said...

George Jr. -- I definitely remember the Commodore 64 and related machines. I came in before punch cards, but the dust from them was still in the air as I entered (so to speak).

I've been trying to remember the name of the computer I had as a teen -- it was a knock-off of an Apple, that I recall.

Alexander R Pruss said...

Doing fairly low level programming when a decent library isn't always conveniently usable, I occasionally use mod to convert a number into string. For instance, one of the easiest ways in C to convert a two-digit number into a string (not worrying about the 0 in front) is something like:

Char s[3];
s[0]='0'+x/10;
s[1]='0'+x%10; /* here is the mod! */
s[2]=0;

So I've been using mod quite regularly.

Dale said...

ARP, my knowledge of C syntax isn't as sharp as it might be, but that looks like a cool trick!