Thursday, October 30, 2008

Programming Styles

Over the years I've met many developers and got to know many different programming styles. Here are some of the odd ones. Do you know someone like that?

Shotgun Programming

It is a programming style where the developer tries random shots at the code. "Well, this method call is failing.... I'll try changing this parameter from false to true!" Then of course it doesn't work and the developer goes: "Well, maybe I could just comment out the whole method call!" and so on. It can go on forever until it works by pure chance or the developer is rescued by a peer who points the correct solution.

A regular developer can go crazy in a few hours if he finds himself pairing with a shotgun programmer. It can drive you NUTS. Two shotgun programmers should never do pair programming together, because their destructive results are magnified when they work together.

Programming by accident

It is a mild form of Shotgun Programming, and it is surprising to see how common it is. I think this category encompasses the majority of developers worldwide by a wide margin. It happens when the developers doesn't really understand what he is doing, but things work. The dev codes some more, and the program still works. Since this is happening by accident, at some point something will break and the dev will have no idea on how to fix it. At this point, he usually has 2 courses of action: stop and understand what he did, in order to find the cause of the error, or, most likely, engage into Shotgun Programming to try to fix the problem.

Test Driven Development came to the rescue of the millions of programmers by accident. Now, you have an excuse to be program by accident: as long as the tests pass, you are good. Don't get me wrong, Test Driven Development is a Good Thing, and it limits the damage that can be caused by Programming by Accident.

Cargo-cult programming

The term comes from the Cargo Cults that appeared in many pacific islands during World War II. During the war, the US used the illands as bases and built airstrips for their cargo planes. The natives were amazed by the planes who brought all those goods and food. When the war was over, the planes disappeared, and the natives built their own air strips, with bamboo control towers, in the hope that if they did exactly like the white men did, the planes would return and bring back the beloved cargo.

Cargo cult programming is the practice of applying a popular solution just because everybody else is doing and it seems to work form them, but without understanding why it is being done that way. Lots of people engaged on it during the first years of J2EE by overusing EJBs and Entity Beans, for example.

Least effort programming

This style is very common specially among junior developers. One day you are assigned a task to fix a NullPointerException, so you just go to the line of code where the exception is generated and surrounds it with a if (reference != null).

It may very well work but you didn't solve the cause of the bug, you just hid it until it comes back to haunt you again. What you should have done is to go back and fix the problem that caused the reference to be null in the first place.

Design pattern driven programming

As the name says, it is the programming style where you use design patterns for EVERYTHING. Your code is full of Facade this, Observer that, Strategy whatever, Adapter, blah blah blah. It reaches a point where you have to dig real deep to find the code that does the actual job in the middle of the Design Pattern Tangle.

Surgical programmer

When working on a bug, the Surgical Programmer investigates the cause. And then the cause's cause. Then, he investigates the consequences of changing the code that is causing the other code to cause the other code to fail. Then he does a text search to find all usages of that class in the code, just in case. And for each match, he does another text search to find what uses the usage's usage. Then he writes unit tests for 30 different possible scenarios, even those that don't have anything to do with the bug he is fixing. In the end, full of confidence and with surgical precision, he fixes a typo.

In the meantime, the regular programmer fixed five other bugs.

Butcher programmer

It is the programmer that has an extreme itch to refactor everything he touches. It is the kind of programmer that, the night before shipping, when fixing a typo in an error message, changes 10 classes, refactors other 20, plus changes the build script and 5 deployment descriptors.

48 comments:

Ochronus said...

Thanks for the article, it was a fun and yet serious post with good points :)

Ricky Clarkson said...

I like it, a lot, but please fix the typo - it's "Test Driven Development", not "Test Driver Development", though there is certainly some truth in the typo.

fsilber said...

Surgical programmer: When working on a bug, the Surgical Programmer investigates the cause. And then the cause's cause. Then, he investigates the consequences of changing the code that is causing the other code to cause the other code to fail. Then he does a text search to find all usages of that class in the code, just in case. And for each match, he does another text search to find what uses the usage's usage. Then he writes unit tests for 30 different possible scenarios, even those that don't have anything to do with the bug he is fixing. In the end, full of confidence and with surgical precision, he fixes a typo.

In the meantime, the regular programmer fixed five other bugs. And in doing so, introduces two or three new ones.

The surgical programmer reduced the number of bugs by one. The regular programmer replaced five known bugs with two or three unknown bugs. The new bugs, being unknown, cannot be fixed at this time.

brisssou said...

looks like fsilber took the whole post for himself...

By the way, I now have to consider myseft as a butcher. I like that.

joonas said...

I would like to apologize for us the butcher programmers for breaking everything — even near deadlines :)

But as working and doing what we do eventually narrows down to other people writing so horrible (object oriented) code. So the blame is on them. Educate them!

Chris Arthur said...

Who is this "normal programmer" and where can find one? It seems to me that this person is much like a unicorn or a UFO and proving their existence is improbable, if not impossible.

LeoGomes said...

I think the stereotype that's closer to how I feel is the butcher one, as well. I mean... I won't touch that 500 lines method without refactoring it, not even to fix a typo!

Bensan George said...

I am very much a design patterns programmer.

Michael said...

Great post. Serious and fun.

I don't think I'm entirely in a specific category, but rather a mix of:
Shotgun: 35%
Cargo-cult: 15%
Least effort: 10%
Design pattern: 0%
Surgical: 30%
Butcher: 20%

Alin Popa said...
This comment has been removed by the author.
Alin Popa said...

Hi Domingos,

I'm not 100% agree with your point about: "Least effort programming": Imagine that the null will come from a 3rd party library that is written very bad and is returning null for some stupid reason ... and you don't have anything to do about it. Also the api doc about that method/class doesn't exists at all (yes, I know it is a very rare case, but trust me, I met this situation).

All the best,

Alin

Martin Wildam said...

In what category would you put those who massively use "frameworks"?

I have been on a course where 80 % of work was done struggling around with XML configuration files and only 20 % of the time producing more or less real code...

Would it be cargo-cult?

Anonymous said...

Cargo Cult... I like that.

There definitely are a few categories missing. The one that I fall into is the category that researches the change and examines the impact, makes the change, and then doesn't test it. It's like half a surgeon. I make the cut, but I don't make sure that it was correct afterward.

Anonymous said...

A great article!! I could identify my self and some of my colleague. Very good!

MTGAP said...

These sound like debugging styles rather than programming styles. Which says a lot about what programming is.

Martin said...

Very good article. I like it a lot. One thing to point out is that all of these programming styles are harmful when it is used too much. However, under different circumstances, they can all be useful. In general, when you are working on a legacy code that you adopted from someone else, you want to be a "shotgun"; when you are trying an unfamiliar algorithm, you want to be a "cargo-cult"; when you are working on a low quality code, you want to be a "butcher"; and finally when you are facing a really important deadline, you want to use "least effort". However, don't overdo it.

Anonymous said...

Good article, almost all of programmer i met before and some just copy and paste directly if they knew they done before without any thinking

Anonymous said...

also, "island", not "illand"

Anonymous said...

Obviously if you've never had to release something in production or even adhere to the idea of not fixing problems you don't have you wont agree, but

if (reference != null) { }

is perfectly valid if you are trying minimize risk and don't have the time to figure out what is causing the issue (cause rather than symptom). Also the experienced programmers can make an intuitive decision about whether that is the best course of action for the problem at hand.

Anonymous said...

Surgical: this parameter can be null under specific circumstances, failure to handle it correctly is a bug.

Least effort programming: screw it, I'll just skip this line if the parameter is a null.

In order to qualify as a least effort programmer, you have to not care why the added test for a null is valid or effective. You just have to care that people stop telling you there's an error.

Least effort is quite a bit "shotgun" as well.

Kirby L. Wallace said...

Don't forget the Channel Programmer. He/She writes five very large scale, highly integrated, database driven web apps encompassing payroll, tech support tracking, document imaging systems with barcode driven archival routing and web portal user interfaces, automatic email generation, central authentication services, etc, all with database access, web service endpoints, JSON and XML protocols, etc, all single-handedly, and all in about just 11 months.

When someone asks him how he did it, he doesn't know. Says he (me), "I dunno. It's not so much that I design this stuff as much as I just channel it..."

;-)

Merrick Christensen said...

I disagree with things getting lost in a pattern. And if you do get tangled, you probably aren't doing your patterns right.

Anonymous said...

Surgical is how it's done in any enterprise development. It's the correct way to correct PROBLEMS.

Chris Forbes said...

> These sound like debugging styles rather than programming styles. Which says a lot about what programming is.

Well, if debugging is the process of removing bugs, then programming must be the process of putting them in.

Anonymous said...

I think the shotgun approach is sometimes a good way to understand what exactly happens. If you change a boolean or comment out a method call, you can relatively quickly get a better understanding where the problem is. Of course, that only works with scripting languages when you don't have to recompile everytime you change something.

Anonymous said...

it seems to me that it doesn't really matter what type of programmer some is as long as he delivers what the spec asks for, that's why we are being paid for.

funny article though...

best,
110j

George Kharmujai said...

surgical programmer - 50%
Programming by accident - 25%
Cargo cult programming - 25%

Anonymous said...

Glad to see Michael above is giving 110%!

Paul Woods said...

You forgot the lazy programmer who leaves everything to the last second and then provides a piss poor solution.

Nei Rauni S said...

Good article, but I think that these styles not cover all.

like:

Paul Woods said...

You forgot the lazy programmer who leaves everything to the last second and then provides a piss poor solution.

sophia said...

I am a Butcher programmer.. shame for me..

Rick said...

That's funny! Thanks for the post.

Rick

david said...

Why stop now? So close to pointing out the negative in every type of programmer! Not only is the glass half empty, the water isn't bottled.

Anonymous said...

Great article! It is so true...

night-fairy-tales said...

Intresting article. Thanks

DeepdarkSecrets said...

in this article you haven't describe the person who were engaged in fighting with frameworks , XML and Configurations . we spend 10% on real programming and 90% time on setting configurations...lolzz...

peter said...

Shotgun: 10%
Cargo-cult: 10%
Least effort: 5%
Design pattern: 30%
Surgical: 30%
Butcher: 15%

Anonymous said...

These count for web development as well. I'm so forwarding this.

ScoutKnifez said...

mwuhahaha.

until the very last line noone could have figured out that you are a java programmer ^_^

squith said...

Well, the importance of the C / C + + is so high that you can call the Foundation for the programming. " So, who wants to enter the world of programming must use your C / C + + skills as a gateway.

Dubturbo

Rap beat maker said...

Shotgun programming, id never heard of that term before, it suits the way i work sometimes though!.

J Smith said...

I'd say I fall under "shotgun programming"... but I'm probably in denial. I usually don't know what to do when something breaks. "Programming by accident" for me :(

Dub Turbo Review

Anonymous said...

I think I definitely fall under the hat of butcher programmer. dub turbo

dubturbo said...

Shotgun programming hasnt been something that I was aware of. I am now and I really think it's a bit out there.

dubturbo said...

Never heard of shotgun programming before, so thanks for the enlightenment!

DubTurbo Review said...

Thanks for the insightful post. Learnt a thing or two about programming...

Jeremuel Raymundo said...

hahahahaha!!!

Jeffrey Aguilera said...

TDD is not a Good Thing.