I Hate Patterns

I strongly dislike them. Here’s why:

I’ve seen more horrendous programming sins committed in the name of patterns than almost any other possible justification. “Optimization” is close, but somehow I’m more forgiving of that - at least the developer is attempting to be concerned with the operation of the application as opposed to the padding of his resume.

There’s nothing inherently wrong with patterns. They are the distillation of experience into easily recognizable chunks that can be applied to common, frequently occurring segments of problems. You can see them everywhere - in mathematics, physics, mechanics, and yes, even in computer science and programming.

They are, however, a second order tool. They are what you use to refine and speed up your development process. They’re not a substitute for actual understanding of fundamental programming and algorithm design principles. Nor do they take precedence over first order principles.

What am I talking about? Let me give you an example. Here’s the real world:

A senior developer, with 2 developers reporting to him, designed and implemented a subsystem. The need arose for what seemed to be a minor modification, and the developer responded with an estimate of two weeks. We were puzzled - the change had every appearance of being simple. I’d have thought less than a day.

So we dug into the implementation. The developer presented the design of the subsystem. He had used EJBs along with the (name withheld to protect the innocent) pattern. The design hung together fairly well. But there was one glaring problem:

The entire subsystem could’ve been implemented with a fraction of the complexity by using a simple servlet connecting to JDBC. If you wanted to be fancy you could’ve used some abstraction of the database. That’s it. Really quite simple.

We gently pressed the developer on his design choices and why he seemingly favored the complex over the simple in almost every instance. He responded with the usual list of suspects: transactions, scalability, maintainability, ease of understanding.

Good list. Here’s the problem: we didn’t need transactions. Scalability doesn’t hold up: look at the highest scaling systems and you’ll see they’re not EJBs. In any case, servlets would’ve scaled just fine for our purposes. Maintainability and ease of understanding are easy to gauge: it’s easier to understand and maintain less lines of code. Less lines of code good, more lines bad.

Then we looked at the actual code. Good Lord. Copy and paste of major pieces into a several files. Justification? Horrible misuse of the poor, innocent factory pattern. Lines of code? Many. Many. Innocent patterns slaughtered everywhere.

We actually spent quite a bit of time with the developer, attempting to reform him. He was a good, smart guy, worth saving. Unfortunately we were unsuccessful, primarily because he sincerely believed he was right - he was using EJBs and patterns. How could the simple, lowly servlet be a better path?

At the end one of our other developers rewrote the entire subsystem in his spare time in far less than two weeks. Lines of code? Something like 1/5th to 1/10th of the original. Faster. Understandable. Simple. The original developer moved on to create many many lines of code for some other company.

Is this really a damnation of patterns or the case of a bad developer? My point is, this guy was not born a bad developer. He was quite smart, and could’ve been useful. There are many of this guy running around. I’ve seen them.

The problem is, he embraced second order techniques, EJBs and patterns, in place of a first order principle, simplicity.

So when you go out there preaching patterns to the masses, remember the real world. And remember boys and girls: Simple is good. Less lines of code good. You don’t need to throw around the latest acronyms and pattern names to be a 10x programmer. Trust me, I know a lot of those guys too, and most of them couldn’t tell you what that fancy pattern name you just dropped means.

7 Comments so far

  1. Chris on July 18th, 2005

    Hear, hear.

  2. […] « Ajax Gems Pattern Abuse Tony Darugar hates patterns: I’ve seen more horrendous programming sins committed in the […]

  3. Mark W. Shead on July 24th, 2005

    Dangers of Design Patterns

    Here is an interesting discussion about the dangers of design patterns. Design patterns can be a great way to solve problems, but many times they become an excuse to over-architect solutions. Design patterns should reduce complexity. If they introdu…

  4. Glen Cooper on March 1st, 2006

    This is like saying I hate XML because so many people throw around the term as if it’s the solution to everything and should be natively embedded in every solution. Or I hate Ajax because people think it should be used everywhere. Or I hate hammers because I’ve seen a lot of people use the wrong hammer for the job.

    The point is Design Patters - just like XML, Ajax or Hammers - are just tools to help us do our job. Of course if you apply the wrong tool to the job you are going to fail miserably. A sledgehammer is not the right tool for hanging a picture. But used in the right way Patterns are a powerful language to help communicate common models, concepts, and approaches to developers.

    I believe this is the point your article ended with, but to lead off with an inflammatory statement like “I Hate Patterns” is just as silly as saying “I Hate XML” or “I Hate Hammers”. If you hate patterns for what they are - fine. If you hate them for how they are misused - that’s something else.

  5. Parand Darugar on March 1st, 2006

    Glen, good point, but let me go on record as saying I also hate hammers and XML ;-)

    Here’s why I don’t like patterns: based on my observation, they have on the whole had a more negative effect than a positive one on the masses of programmers. Putting aside the theoretical benefits or problems, in practical terms, they’ve been a negative, at least from what I’ve observed.

  6. hilquias on March 1st, 2006

    every developer know this. sorry im stoned

  7. Russ Olsen on March 1st, 2006

    I’m sorry to say that while I think design patterns can be a great tool, I’ve seen all too much abuse along these lines. I once inherited a GUI where every menu item was wired to a command which did nothing but grab a factory and create an accessor which did nothing but grab a factory and create a… Well you get the picture. People who write this stuff just seem to miss that the size of the infrastructure needs to be in proportion to the size of the actual work being done. If the infrastructure is four times the size of the code that actually does something, then you can rewrite the real code 4 times for the price of the infrastructure. Kind of puts the ’savings’ from all the infrastructure in perspective. There is no substitute for real engineering.

    Good article.

Leave a Reply