Log in

No account? Create an account

Previous Entry | Next Entry


Code quality

  • 6th Jul, 2005 at 11:59 PM

Kid on a bike
Originally uploaded by sfllaw.

Last night, I left work and headed for the gym. I hadn't been there in a long while and was noticing that I was starting to lose the scant muscle tone I had gained. I walked through the muggy streets and let myself in to the Y.M.C.A. at Peel. I showed my membership to the woman at the front desk and as she handed me some clean towels, she warned me that the hot water had gone out. I thanked her and headed inside.

After my workout, I was tired but feeling high on endrophins. I climbed up to the third floor to return my heart-rate monitor in exchange for my membership card. The guy at the desk looked new and inexperienced. This is because he seemed very rattled whenever I talked to him. Oh yes, and I had to tell him where the monitors were kept. This started me thinking about Zen and the Art of Motorcycle Maintenance (ZAMM).

I read ZAMM a couple months ago and it had kicked some thoughts into my mind. But then I stopped reading it and forgot most of what Robert Pirsig had wrote. Which is fine, because I thought he was sort of insane. For one thing, he was really obsessed with Quality (note the capital Q) and I think obsessions like that are rather unhealthy. Not only that, I decided as I walked down to the changing room, I think he was wrong.

But it doesn't really matter—his book got me thinking about quality in general. Or rather, why some things were very good, and most things were very bad. I opened up my locker, wrapped a towel around myself and went into the shower. The water started out freezing, and I started even though I was warned in advance. I turned it up as hot as it would go and it warmed up a bit as I let it run. Maybe the boiler was fixed and was starting with a cold tank? I scrubbed my skin red and thought more about "quality" as a term. It's a property of reality, you see. Not reality itself, but a consequence of reality. Much like "dimension", you can things that are high and things that are low.

Foam faces
Originally uploaded by sfllaw.
I finished with the shower and shut off the water. I wondered if the steam room would still work if the hot water boiler was broken. I turned on the light, walked in, and was confronted by a wall of moist heat. I sat down on the hot tile bench and realised that my breath was colder than the air. It's strange how I've been running the air-conditioner over the past couple of days, but now I decide to sit in a hot, humid room. I figure it's because experience is subjective. For instance, I remember my first taste of coffee. It was black, bitter and acrid. But now that I've trained myself in what good coffee tastes like, I've learned to appreciate its unique aroma and flavour.

I tried another flavour of heat by going into the dry sauna. The sweat that dripped off me in the steam room evaporated quickly. It was very hot in there: breathing out through my nose causes hot air to burn my upper lip. I don't appreciate the dry sauna quite as much, because I don't know how to relax in it. It's sort of like learning a new programming language: earlier in the day, Adam said that after learning one computer language, the others come easily. Well, yes and no. For imperative languages, it's very easy to pick up the syntax of a new language. Within a couple of days, you can churn out working programs in the new language and you can be quite happy. However, it takes years before you actually understand the idiom of the language. Until then, you're just programming in the old language with different keywords. I don't stay in the dry sauna very long as it made me quite thirsty. Maybe one day, I'll appreciate it properly.

After the rain
Originally uploaded by sfllaw.
I hopped back into the shower and this time it felt refreshingly cool. That's subjective quality! I rinsed off, changed, and stepped into the night. It was drizzling lightly; the raindrops were warmer than my shower. Instead of ducking into the metro, I walked east. As I walked down de Maisonneuve, I thought about the code I've had to change recently. I've seen really low quality code. Why would someone write stuff that's that bad?

As I walked, the rain came down a little harder. Soon it was a gentle summer rain, which was a nice change from the hard downpour that morning. Then it came down a little harder. I looked at my watch to see what time it was, but it's been obscured by the raindrops. A taxi driver stuck his head out his window and asked if I want a ride—I declined. I was happy to be walking in the rain. Far happier than all the miserable people huddled under their umbrellas. I got to my destination, the grocery store, bought an few things and paid for them. Just as I stepped out, the rain stopped. Moments after that, the bus arrived. Nice timing! This was really making my night. It was about that time when I started to think about how my mood affects the quality of my programming.

Fruit of the chair
Originally uploaded by sfllaw.
It has come to my attention that when I'm happy and awake, I program better. I make fewer mistakes, produce better designs, and think up better models for the problem space. Sometimes, I'm enjoying programming so much that I stay at work until the sun rises. This is perhaps because programming is a craft, much like hand carpentry. You have to take a look at the grain of the wood, figure out how to best support the loads, cut the wood, sand it down, and join it. You can make a wobbly stool, or a finely built throne. It appears that the same applies to programming: high quality programming needs care and attention to beauty. I think these are necessary, but not sufficient, properties. I see haphazard coding often in real-life; many people that I interview do this when presented with a programming problem. So I imagine that it happens as often when people write code on their own. This disturbs me greatly.

And when I'm upset, I suspect that the same thing happens to me too. I just start writing stuff until it works, then I commit the code. This can't be good for maintenance and it certainly isn't good for my ego. I wonder what I can do to increase the quality of my work when I don't feel like doing it? Can any of this be applied to motivating others to write higher quality code? I shall have to ponder this.


( 8 comments — Leave a comment )
7th Jul, 2005 15:25 (UTC)
I do not own an umbrella, for the same reasons you enjoyed walking in the rain, like I do.

And programming is a craft, yes. Too many see it as soulless typing away at a keyboard.
8th Jul, 2005 05:46 (UTC)
I think I only enjoy walking in the rain when there's no wind and the temperature is adequately warm. I don't enjoy catching a chill, so if there's no risk of that, I don't mind getting wet at all.
7th Jul, 2005 17:58 (UTC)
The problem may be the amount of design-time that one needs to produce elegant code; it clashes with professional environment that just wants functionality, fast. Perhaps that's why so many of the internal tools I've worked on have been so terrible to maintain or even understand.

Perhaps there should be some type of Rinzai Buddhist system for coders, for those that feel that development of mind and body are essential to a process of manipulating electronic reality to do one's will. I'd sign up, anyway.
8th Jul, 2005 05:56 (UTC)
Anyone who's got some experience designing systems knows that you don't just dive into a project. I understand that you can spend forever designing a system before you implement, but there's a fairly good balance between up-front design and refactoring.

But the point is that writing elegant code does give you functionality quickly. Where one defines "functional" as "meets the requirements", as opposed to "looks correct for the one case I tested it on". Whenever there's something inelegant, it gets in the way of getting things done.

I think one of the major problems here is nobody sets out to design inelegant solutions. At the time, the solutions are good enough and the cruft builds up incrementally. There are arguments that the increased efficiency never works out for the time spent improving the system, but I suspect that this argument makes naïve assumptions that don't bear out in reality.

If you decide on using religious belief to program the coders, please note that very few programmers subscribe to Buddhist philosophy, although they are familiar with some of the tenets. It would probably be better to go with some secular meme instead.
8th Jul, 2005 06:29 (UTC)
I figure that, with the amount of material in /usr/bin/fortune that borrows from Taoist and Rinzai teachings (the ones I know enough about to be somewhat comfortable with) there's something about them that holds some non-religious, coder appeal.
8th Jul, 2005 02:27 (UTC)
I write the best code when I can do it in long stretches (12-15 hours at a time) without interruption. I write the worst code when I'm constantly interrupted. My mood matters little unless it's directly related to the project I'm working on (harder to write something that may be thrown away as soon as it's done). I also write best at home, alone, between probably 8pm and 5am, with or without cats (but always with pussy! O:-)
8th Jul, 2005 05:49 (UTC)
I am no longer young, you see, and can't code for more than ten uninterrupted hours without going braindead. If I throw a meal in there, I only really get about four hours. I suspect your later hours stem from the fact that nobody is awake to bother you from 2:00 to 5:00.

I agree, however, that being uninterrupted is excellent for productivity.
8th Jul, 2005 02:41 (UTC)
Putting the K in Quality
I first read ZAMM in high school and have read it several times since. I haven't read Lila, though probably should. Pirsig is definitely obsessed, but I don't think it's all bad. His Quality isn't as bad or damaging as Ayn Rand's Objectivism, for example. For me, the attraction to ZAMM is mostly that it makes me think. I like philosophy (took lots of random philosophy classes in high school) and like reflecting on life, the universe and everything. Plus, it has motorcycles and you just can't go far wrong in my book if you have motorcycles. O:-)
( 8 comments — Leave a comment )