Seven Deadly Sins of Programming – #5

[Several readers pointed out that I made a mistake in phraseology, and didn't say the thing I meant. Thanks to them for knowing what I wanted to say more tha I did.]

Thanks to all who have commented on the previous sins, and to those who have written their own lists. I have avoided reading them, but I will take a look when (if...) I get done with my list, and I'll write a summary post linking to them, and likely listing the ones that I would have put on my list if I'd only been a bit smarter and a bit more thoughtful.

Back when I was a pre-teen, I thought I really knew what was going on. I didn't need my parents advice on what to eat, or who to hang around with, and I *certainly* didn't need their advice around oral hygiene.

So I didn't brush my teeth. Oh, I'd rinse my mouth out, but no actual brushing.

This didn't cause any problems - my teeth were fine when I went to the dentist. No worries.

For a year or so. Then I had to have 4 cavities done in one fall. Big cavities. Cavities that weakened my teeth enough that I'm slowly buying my dentist some nice accessories for his boat, as they start to crack and I get crowns put on.

Code hygiene is also important.

Back when I started coding, my teacher (who I am in debt to for being at least 10 years ahead of his time and setting up a real programming curriculum (no, we didn't use abacuses...)) made us write down our programs on paper before we were allowed to use computer time. Not only did you have to write it down, you had to show it to him, and if it wasn't good enough, he'd make you copy it from scratch with the necessary changes.

When I got better, I got introduced to my first text editor. Line oriented, a real improvement. Rather than typing a line over, you could make changes to it.

Then, the fateful day came when I got to use a screen-oriented text editor. You just used the arrow keys, and you could make changes *right in your code*.

Very powerful. And very dangerous, because it supported


(Cue emphatic and scary music).

Copy and paste is not a sin - it's actually quite a useful thing, but features like it make it far too easy to do bad things. Need a function that's almost like the one you have? Copy and Paste. Need to add another conditional into that double-nested loop? Just insert it in there. Need a class that's almost like what you have? File copy, then search and replace to change the names.

Which leads to too much function complexity and duplication, and to our fifth sin:

Sin #5 - Deferred Refactoring

Once you start deferring refactoring, things get bad. Even if you have good intentions to come back and "clean that up a big", you often don't.

That's why I find agile methods and shared code ownership so interesting. If there are good tests in a codebase, I can find the ugly code that a coworker has written and refactor it into something nicer rather than just trying to get picked to work on "the new codebase"...

Now go brush your teeth, and it wouldn't hurt you to floss sometimes...

Comments (13)

  1. zzz says:

    4 big cavities appear in one year?

    I’ve heard of a person going to a dentist and then right after to another and there was a huge difference in what they’d find.

    Before settling on one regular dentist permanently it might be good idea to see if another gets same or atleast nearly same results in a normal check of cavities.

    I had planned to do so but didn’t and now 10 or so drilling and few root canals later I’m feeling quite strongly about getting a second opinion before any more major work.

  2. Yes, it’s the return of "Picky Paul"…

    Surely it’s Copy And Paste that’s the deadly sin, and as you rightly point out, Cut And Paste can be quite a useful tool if used with caution (a sort of poor man’s refactoring).

  3. Niall says:

    From the last part of the post, does this mean that #4 will be something along the lines of "Misunderstanding Test Driven Development" or "Writing Unit Tests When It’s Convenient"? Arrrrrrrrrrrg…

  4. Darren Oakey says:

    Cut and paste is fine

    Copy and paste is almost always a sin 🙂

  5. Darren Oakey says:

    I made these a while ago, when you made the first post – my seven deadly’s

    * copy and paste – duplicated code is bad, and duplicating it is worse.   The first is a maintenance nightmare – the second misses the chance for a great refactoring AND creates a maintenance nightmare.

    * code with side effects

    * PLANNING a generic solution.  (you come up with a good generic solution by implementing a few specific solutions a few times, and extracting the common elements, NOT by planning it in advance, because there is 100% chance of you being (VERY BADLY) wrong

    * collecting things of like type together (eg all the forms, or all the enums)

    * collecting things in the same layer together (all the ui components)

    * doing releases/builds or testing manually as opposed to with a script

    * making any assumptions about external interactions that aren’t guaranteed in some programmatic way.  eg – assuming a nullable field in the database won’t have nulls in it, because you absolutely "know" that nothing can put a null into it.   Or that the total field is actually equal to price1 + price2.

  6. ericgu says:

    zzz – My teeth have deep valleys in the middle of them, so it’s pretty easy to get decay in all of them. It happened to my mom, happened to me, and with any luck – and some sealants – it won’t happen to my daughter.

    Several dentists have told me that the original cavities were "nice work", and my current one shows me the cracks on his tooth-o-cam, and we’ve been addressing them as necessary.

    Paul et al. –

    I hate it when I do that. Yes, it’s copy and paste. I’ll update the post.

    Niall –

    Yes, it does.

  7. Wife PhC says:

    I of course puzzled through what your intorduction had to do with the price of beans but then it dawned on me…Early child using PASTE good thing…Programmer misusing PASTE bad thing.  Nicely Done.

  8. Mark Wan says:

    It seems to be an age thing – on an era thing.

    I think I am as about the same age and was brought up with line editors (remember teletexts?) and I am very cautious about copy-and-paste.  Then in the 90’s I watched some younger person doing coding in Excel VBA and she was generously copy-and-pasting.  I remember the same emotion as Eric was trying to instill.  When I talk to the person about it she said that’s what all her peers do…  This lead to one of my colleagues to say that Microsoft promotes bad coding practices because they introduced Windows and make copy-and-paste ubiquitous.  🙂

    Then about 2 years back another young programmer said to me the preferred approach is cut-and-paste and avoid copying.  Well those young folks finally have some sense…


  9. So, the time has come for the worst sin.

    Just to recap – and so there is one post that lists them all…

Skip to main content