masochistic

Dec 05, 2007 10:30

In my old job I used to write Unix shell scripts all the time. In the last four years I've written... maybe one.

We've been having problems with our DHCP server running out of leases in certain areas, and we needed a "right now" way to tell when this is happening. So I broke out the rusty old script skills and started writing. It came back to me surprisingly fast.

This was a trivial script - there was nothing complicated about it at all. But it rekindled those feelings inside of me. (Any coders who are reading this undoubtedly know exactly what I mean.) I love this stuff. I'm not good at it. My scripts are like stone axes compared to some of the ceramic scalpels that other coders can create. But it's still an incredible feeling to create something out of nothing and make it work.

And yet, it's an inherently masochistic pursuit.
It starts out simply enough:
1. What's the problem?
2. How do I solve the problem?
3. Now break the solution down into bits in a way that can be automated and coded.
4. Write the code.

But #4 is where the fun starts. As soon as you start writing the code, you start running into the roadblocks. I want a variable returned that is a number representing the day of the month - simple. Umm. But do you want it as "5", as "05", or as " 5"? How do you make it come back the way you want it? So you fiddle with things and make that work. Or make it so it appears to work. But did you test every possible iteration? The way you coded it, every third Tuesday in odd numbered months in even numbered years you'll get an error. Or something equally esoteric.
But none of that really matters because you used single quotes when you should have used backticks. Oops. Or double quotes inside of single quotes. Or you forgot a semi-colon. Semi-colons are the bane of my existence when I'm coding - I always manage to forget one, somewhere.

Writing a complete working script is kind of like running head first into a brick wall repeatedly, until either your head or the wall caves in.
You run headfirst at the problem and the program doesn't work. Boom. So you go through it and find the place where you missed a semi-colon. Cool; it's all good.
You run again... boom. You misspelled that variable there and it returned a null value. Fixed it.
Running... boom. More syntax or spelling errors.
Eventually, you get those sorted out and the program runs. But it doesn't work. Oh no, that would be too easy. Now is where you get to discover, one at a time, all of the exceptions and problems and situations that you didn't think of when you first looked at the problem. And each time, your head slams into that brick wall.
And each time that you figure out the problem and fix it so that you can try again, you get that little reward tingle in your head. "I found the problem! I am the greatest! Go me!" And then you slam into the wall. "Crap. Will this never end? Maybe I should just give up and go play Minesweeper instead." But you hunt some more, and find the next problem, and keep going.

And I love this why? I'm not sure. But I do.

scripts, coding, craziness

Previous post Next post
Up