Mistakes are the portals of discovery – James Joyce

“Ahh poop” or words to that effect, could be heard resounding through my flat in the middle of last week. Throwing away code is hard. I’d just worked out that the 3 classes I’d written, were wrong. Worse, the 3 sets of tests that I had written (first, test-first), were now useless. The code wasn’t bad, but I hadn’t thought about how to solve my problem well enough. You shouldn’t http POST to a URL query, its just not right, e.g. http://www.david.com/service?day=wednesday&recordfootball=true

Throwing away code, however, is a good thing. It means you’re learning, it means you are raising the bar of your own efforts. (Refactoring code is very different, and is a tool every agile developer should have, sure, refactoring can be painful too, but never as painful as throwing away code). If you don’t throw away code, that you know it fundamentally wrong in its functionality, because you are too attached to the code, things will only get worse. It also teaches you a lesson in checking what you are doing, at a business logic level, is correct in the first place. This also taught me a lesson about the advantages of pair programming.

Unfortunalty, I am unable to pair on this project as it is something I am doing in my own time, but I suspect if i was pairing, somewhere along the line someone would have said “what are you doing that for?”.It also got me thinking about code reviews. I’ve never really been involved in one, but I’ve made a resolution with myself to try and do it. Just take a class I’ve written and go through it with some of my colleagues at work, because i know there must be better ways of doing the things I’ve done, and similarly, i think there are a few tips I can teach people by looking at my code. Far too often in the IT world the person that wrote the code owns it, that is “badness”.

Thinking about it more, i think it shows a degree of honesty with yourself when you throw away code and allow it to be reviewed. Programming is not an art form, despite what people say, its deterministic, and so, in fact, it takes a clever person to know when there code is not useful, or unperformant.

So, in fact I reckon I’m in profit after my c# malfunction. Having written 3 useless classes and 3 useless test classes I’ve made my code more useful, thought about how i can use code reviews to learn and teach different techniques at work, appreciated the value of pair-programming and well, filled up some more space on my blog. J

p.s – this made me laugh. Say you have 4 telephone numbers that you can input on a form to set up a conference call. You name each variable logically, private String telNumberOne , telNumberTwo etc. But you think, well pretty much everyone knows what you mean when you call it a telNo so ill refactor my code to call the variables telNoOne, telNoTwo. Except when your in a live meeting and you try and get your colleague to look at the the first phone number

David : “Look, you see telNoOne”

Colleague : “Tell Noone about what? Your code? Why?”

Although this wins as a (how not too) guide on variable naming conventions : http://mindprod.com/jgloss/unmainnaming.html

Advertisements

5 Responses to Mistakes are the portals of discovery – James Joyce

  1. DE says:

    Code reviews allow someone to point out mistakes after they happen – which is a bit late! Its also easier to see someone elses mistakes after they have made them, then spot the process as it happens.

    Coding, like sex, is something you can do on your own, but it may not be quite as productive.

  2. Paul Downey says:

    ” Programming is not an art form, despite what people say, its deterministic,” which shows the programming languages you’ve been exposed to 🙂

  3. DE says:

    ..and maybe what platforms 🙂

  4. davidjames says:

    Deterministic: Referring to events that have no random or probabilistic aspects but proceed in a fixed predictable fashion.

    Sounds like a “compute”r, to me.

  5. Gary Casey says:

    An anecdote … When I wrote the first alpha version of what later turned into http://www.openadaptor.org, my boss at the time, Andrew Weir, gave me two months to do what we had agreed I should try to do. Every week, and later on, every day, he would ask me how it was going and could I show him anything, and just about every time until really the last week or so, I had to give him the same answer, which was “Not much. I threw away all my code again last night.” My memory of that time is getting hazy now, but I believe I threw away all of my code about 9 times during those two months at the end of 1998. And each time, I learned more. My understanding of the problem space improved. My mental model of the solution to that problem improved. I reckon if you’re not throwing away lots of code when you are tackling a problem that is very novel or unfamiliar to you, then you are extremely unlikely to solve the problem effectively. We learn by doing, whether it’s learning to walk as a baby, or building rockets in the Soviet space program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: