The seven sins of programmers

Fixing bugs in the coder, not the code

Download the whole article as PDF

Write a full post in response to this!


Programmers. The system administrators worship their bit twiddling capabilities. The users exchange vast quantities of beer for new features and tools. And the project managers sell their souls when they make the magic work. But inside the average programmer’s psyche are several demons that need exorcising.

Pride

This is all too common in programmers. Instead of asking whether a particular function exists, or for the best way to retrieve data from the system, a proud programmer is likely to write their own. Especially when faced with a large, or unfamiliar, code base. By re-inventing the wheel there are now two very similar routines. Not only does this increase the code size, it doubles the amount of maintenance required, creates another opportunity for bugs, and adds inconsistency. Later, when another programmer sees these two functions, they will have to choose between them. Which one will depend on their mood (are they also too proud to seek help?), who’s on holiday or who’s outside smoking, at the time! This can equally be applied to duplicate constants, member variables or structures.

Code reviews… must focus on the code, not the coder

Code reviews with a senior team member can help quell a developer’s pride, and guide the other developers in the appropriate direction. This is basic employee training, and one that is simple to implement. Reviews also force the developer to reason each decision made, and justify the creation of new utility routines, perhaps explaining to the lead why existing standard code was not used. To be constructive the review must focus on the code, not the coder, and support free flowing ideas, regardless of the relative seniority of the reviewers. Remember that if the developer is too proud they’ll be closed to ideas, or won’t suggest improvements.

Envy

Programmers should improve themselves by learning from others, not blindly emulating them. All coding methodologies (be they syntactical or design-based) come with caveats. A programmer might inline a function with the pre-processor because he’s seen it done elsewhere, unaware of potential side effects, as in this classic example.

#define SQUARE(x)   x*x

Similar evils occur when programmers move between languages. An experienced developer will typically have a specific style that he tries to crowbar into every other language. Perl written like C. Java written like Ruby. We’ve all seen the examples. Naturally, you should use the best tool for the job, and work to the strengths of that language. By trying to fit idioms from one language into another highlights the fact you understand neither. It’s a development fact of life that some languages are better suited to some tasks, so adapt to it, and close those envious eyes that look at the language you’d rather use. Remember the oft-quoted saying, “When all you have is a hammer, everything looks like a nail”.

Gluttony

Not an evening at the all-you-can-eat buffet, but the problem of writing too much code. Every hour spent coding will require an extra hour of testing, and possibly two more of maintenance. And guess who gets lumbered with the maintenance?

Worse still, this does not scale. A two-minute feature (or one line bug fix) may also take an hour to test. Whatever your gluttonous reasons are—attempts to impress, an under-staffed team, late night camaraderie, or personal pride—curb them. Spending the whole morning trying to unravel last nights two-minute feature is like the buffet—you get stuffed afterwards!

Lust

Programmers crave pleasure; they love to “scratch their own itches”. If unchecked, some developers will write fantastic, innovative, original… and completely unnecessary, code. It could be a new graphics shader, a faster search algorithm or an entire processing engine! If you’re working on anything other than a pet project, you will probably have a schedule that must be adhered to, and a set of pre-determined priorities. These affect the whole project, and not just the wanton lust of an individual developer. Unless you are called Spock, the needs of the many, outweigh the needs of the few… or the one.

Make sure any code written is actually needed. Will it get used? Or will it distract the users who, in turn, add a new plug-in system, just to make use of the code? One very common example of this is premature optimization. Without profiling the code it is impossible to tell exactly where the bottlenecks will occur. Granted, most developers can look at a function and give several reasons why it is slower than it could be, but very few can tell you want percentage of the total running time that function will occupy. Unless it’s known to be on the critical path, then it’s probably not worth optimizing at this time.

The desire to write new code can also exclude the possibility of introducing middleware as a viable solution. The cliché chant is then of “Not Invented Here”. Programmer X once said,

“I’m not using middleware since I don’t understand it; it’ll be just as quick to write it myself. How can I be expected to maintain something I don’t understand?”

Don't miss out on the other pages!
12next ›last »

Write a full post in response to this!

Similar articles

0

Do you like this post?
Vote for it!

Copyright information

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html.Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html.

Biography

Steven Goodwin: When builders go down to the pub they talk about football. Presumably therefore, when footballers go down to the pub they talk about builders! When Steven Goodwin goes down the pub he doesn’t talk about football. Or builders. He talks about computers. Constantly... He is also known as the angry man of open source. Steven Goodwin a blog that no one reads that, and a beer podcast that no one listens to :)

Anonymous visitor's picture

good one

Submitted by Anonymous visitor on Tue, 2007-04-03 06:50.

Vote!
0

good one

Anonymous visitor's picture

"try and curb"

Submitted by Anonymous visitor on Tue, 2007-04-03 16:28.

Vote!
0

...should instead read "try to curb". Also, some of the material was shoehorned a bit too much in order to fit the biblical sins. Otherwise, a fine article.

Anonymous visitor's picture

what is the side effect?

Submitted by Anonymous visitor on Tue, 2007-04-03 17:44.

Vote!
0

So, what is the side effect?
#define SQUARE(x) x*x

Edward Macnaghten's picture

Side efect

Submitted by Edward Macnaghten on Wed, 2007-04-04 01:13.

Vote!
0

A line like

y = SQUARE(x++);

would evaluate to

y = x++ * x++;

which is probably not what is required

Anonymous visitor's picture

Even easier...

Submitted by Anonymous visitor (not verified) on Mon, 2007-04-30 17:41.

Vote!
0

y = SQUARE(x++);

Actually, SQUARE(1+1) would become 1+1*1+1 (=3). Then, the smart comes and defines:


#define SQUARE(x) ((x)*(x))

Just to later find out that s/he was not that smart, because it does not solve SQUARE(1+1).

Anonymous visitor's picture

Side effects of #define SQUARE()

Submitted by Anonymous visitor on Wed, 2007-04-04 00:27.

Vote!
0

The square function may already be defined with other options as well.

Square function for multiplication may be a quick hack, but if you already have a function #define SQUARE() for a different area of the program (ex. - dimension of a box rather than a number multiplied by itself), you can run into a lot of pesky unrelated errors.

Anonymous visitor's picture

#define SQUARE(X) is not a

Submitted by Anonymous visitor (not verified) on Tue, 2007-04-24 09:03.

Vote!
0

#define SQUARE(X) is not a function!

Anonymous visitor's picture

Interesting, but perhaps you missed one sin, arrogance...

Submitted by Anonymous visitor on Wed, 2007-04-04 01:21.

Vote!
0

I think the author has committed the sin of arrogance.
To charge other programmers with sin simply because they
must develop useable software within a timeframe that does
not allow them to study the complete scope of a language or
application framework.

One caveat: I am a "born again" coder of functions which may "duplicate" other existing software. I learned that I can spend more time learning how to use existing software than it takes to code a duplicate module. Plus, I don't waste time debugging someone else's code because they gave up trying to find a fix a thorny problem but didn't make any note for others who may trip over it.

My biggest sin? I use flat files for database applications which have less than 100,000 records. They are always compettive with SQL databases in performance and can be developed in one tenth of the time.

All that said, I enjoyed reading this article and encourage others to consider these ideas with the thought that they should be applied in moderation.

I look forward to reading more of your articles Steven.

wurakeem's picture

somewhat agree

Submitted by wurakeem on Tue, 2007-04-10 17:28.

Vote!
0

I agree with you and the author. My personal approach: borrow if you think you need to borrow and write when you can.
Notice my wording: most programmers don't like borrowing so they do it when they really need to. Otherwise write if the environment permits. I am in the financial field so development with component reuse is standard under constant deadlines.

borrow vs. roll your own really boils down to 4 main factors:
1. time alloted to complete project
if you know your schedule then you can very easily determine whether a fancy approach or a pedal-to-the-metal approach would fulfill the requirements.

2. management opinion about the approach
if your higher-uppers are all about buying components or encouraging or expecting your code to use existing infrastructure, it would be dumb on your part not to follow that. If they're okay with you building on other dependencies and give you the time to do it, why would you argue ?

3. great ability to estimate time it would take.
This is something that all developers should try to hone as much as possible. This is a crucial skill that will save your tail in the line of fire and will make you shine when it comes time to deliver. If your estimate says that reading docs and learning the API would take longer than writing your own implementation then so be it. Don't make a decision based on your opinion about reuse, but based on the time cost.

4. know when to stop
This is another big pet peeve with developers. Let's say you wrote an app from scratch and it is 70% complete. Suddenly you notice that there's a much better (even standardized) way of doing it, using a 3rd party library. You start reading the docs, you play with the API but you're stuck because of some errors you get with the API. Whether it is your fault or the library's fault, if your time is running out you must revert to the old approach and finish it. Maybe when management approves this new approach you can call it version 2 and tell them it will take a little longer due to this issue you encountered. Just don't get bogged down trying to do it the "right way" first time around.

Anonymous visitor's picture

Antipatterns and the seven deadly sins

Submitted by Anonymous visitor on Thu, 2007-04-05 17:53.

Vote!
0

I saw something similar to this in the Anti-patterns book (ISBN 0-471-19713-0) which has been around a while. Who attribute the idea to a book called the Online Deskbook.

Their seven sins are:

Haste: they talk about compromising because of time.
Apathy: they talk about not wanting to solve known problems.
Narrow-mindedness: they talk about refusing to practice solutions that are otherwise known to be effective.
Sloth: Poor decisions based on the easiest answers.
Avarice: (Greed) They indicate there are a number of types, but discuss architectural avarice which means the system is overcomplicated with excessive detail.
Ignorance: The intellectual sloth, not seeking to understand.
Pride: Not-invented here.

I think that the front-matter of this book is definitely worth a read. It also some interesting reasons as to why software projects fail. Which have been reproduced here.

On a separate note, whoever runs this site, if I could leave my name without registering I would. Why should people want to register on every blog they write on--- Drupal is quite capable of accepting names and personal details for one-off posts. Why not turn it on?

Infernoz's picture

It all depends on the social environment and constraints

Submitted by Infernoz (not verified) on Thu, 2007-04-12 07:52.

Vote!
0

Please everyone read the "Peopleware" book, it was like an epiphany when I saw that some people genuinely understood what can go wrong in creative environments and how they can be improved. A sub-optimal or unstable environment can be a far worse barrier to development than developer behaviour and actually cause developers to misbehave.

hDrummer's picture

Pride Envy Gluttony Lust .. L

Submitted by hDrummer (not verified) on Fri, 2007-04-20 07:15.

Vote!
0

Pride
Envy
Gluttony
Lust
..
License
Biography

;)

Anonymous visitor's picture

Mentifex is guilty of all coding sins and then some!

Submitted by Anonymous visitor (not verified) on Tue, 2007-05-08 13:27.

Vote!
0

Another sin I'm guilty of is looking at these disturbing, accusatory articles (such as we see here) and getting so depressed about my past failures that I sink even more deeply into failure.

Hari's picture

Good one

Submitted by Hari on Wed, 2007-05-09 08:30.

Vote!
0

Good one

Kahuki's picture

Hehe, very good idea!

Submitted by Kahuki (not verified) on Sun, 2007-06-03 11:59.

Vote!
0

Hehe, very good idea!


From the FSM staff...

Odiogo