views:

1511

answers:

16

How important are Design Patterns really?

I think the earlier generation of programmers didn't use Design Patterns that much (people who graduated in the 80s and before mid 90s). Do the recent graduate know it in general and use it a lot more?

If you are interested, I also made a survery and you can view it here:

http://www.surveymonkey.com/s.aspx?sm=kJOdGX0RPx5FGrfPVm_2bmIw_3d_3d

Update: Here are the initial survey results:

http://img192.imageshack.us/img192/7107/surveyresults.png

+37  A: 

The single biggest benefit of design patterns in my opinion is that it gives developers a common vocabulary to talk about software solutions.

If I say, "We should implement this using the singleton pattern", we have a common point of reference to begin discussing whether or not that is a good idea without me having to actually implement the solution first so you know what I mean.

Add in readability and maintainability that comes with familiar solutions to common problems, instead of every developer trying to solve the problem in their own way over an over again.

Pretty important. Software can be made without them, but it's certainly a lot harder.

Matthew Vines
So now we have every developer trying to solve problems in the same few ways, no matter whether they're appropriate. That the example you came up with is Singleton is telling - I suspect that pattern alone has caused more bad design than all explicitly named design patters together ever have caused good design.
Michael Borgwardt
But aren't you glad that you can tell people not to use the singleton pattern in certain ways, and they know what you are talking about.
Matthew Vines
The Singleton pattern may be used poorly in a lot of cases, but considering the alternative for most of the people using it poorly would be an abundance of global variables, I think it would be hard to blame bad design on the singleton pattern's existence.
Gerald
Not all that hard - I think people would be more reluctant to use global variables, since those have been long established as a bad thing - but with Singleton, the fact that it has a name and is a Fully Recognized GoF Design Pattern seems to make people forget that it's basically just a disguise for global variables.
Michael Borgwardt
+18  A: 

They are not absolutely needed, but the good definitely outweighs the bad.

The good:

  1. Code readability: They do help you write more understandable code with better names for what you are trying to accomplish.
  2. Code maintainability: Allows your code to be maintained easier because it is more understandable.
  3. Communication: They help you communicate design goals amongst programmers.
  4. Intention: They show the intent of your code instantly to someone learning the code.
  5. Code re-use: They help you identify common solutions to common problems.
  6. Less code: They allow you to write less code because more of your code can derive common functionality from common base classes.
  7. Tested and sound solutions: Most of the design patterns are tested, proven and sound.


The bad:

  1. Extra levels of indirection: They provide an extra level of indirection and hence make the code a little more complex.
  2. Knowing when to use them: They are often abused and used in cases that they should not be. A simple task may not need the extra work of being solved using a design pattern.
  3. Different interpretations: People sometimes have slightly different interpretations of design patterns. Example MVC as seen by django vs. MVC as seen by Ruby on Rails.
  4. Singleton: Need I say more?
Brian R. Bondy
I totally agree, but your criticism (1) would seem to apply to specific patterns rather than the Design Patterns concept. Altho most common design patterns are based on levels of indirection.
Shane Powell
I had to laugh when you added 'Singleton'. It's been a thorn in me side for a number of years!!!
Shane Powell
:) I added it mostly for humor, but global state and restricting yourself to only one of something isn't a good thing anyway.
Brian R. Bondy
+5  A: 

Important isn't the word that I would use. I would use the word "helpful". Giving developers a common language to describe frequent problems/solutions is useful -- moreso in a collaborative environment.

micahtan
+2  A: 

Great question! I wast just asking myself that question about a week ago. I use them whenever I can, but I don't really find lots of opportunities to use them. I personally think that the idea of Design Patterns is great. Mechanical engineers and Electronics engineers don't design from scratch, but applying well-understood patterns that among other things allow newbies to stand on the shoulders of the knowledge laid by their predecessors. Design Patterns are a step on the right direction, but much more steps are needed.

Kwang Mark Eleven
+48  A: 

We used design patterns in the 80's, we just didn't know they were design patterns.

Javamann
Hah! Classic.
micahtan
true... true...
J.13.L
That's almost self-prophetic. This should be the accepted answer.
Robert Cartaino
+6  A: 

I think you miss the point on what a Design Pattern is.

In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design.

So design patterns are just a formal language to define common ways to solve software engineering problems. I would think most people are using design patterns without knowing that they are. So these common solutions to software problems can date back a long way, they just hadn't come up with a formal language to describe what they where doing.

I think design patterns are important because they teach you the command ways to solve the problems in the areas that design patterns apply to.

Shane Powell
A: 

Design patterns are taught in design classes for CS. They aren't essential, but really helpful if you can find analogous situations to have a solution that has been thought through.

It also allows programmers to communicate more easily. You can talk to your coworker in terms of the patterns as well. If you say here I have my Observer, then it is pretty well understood what is kind of going on.

People will naturally come up with solutions that will fit into a design pattern on their own, but the design patterns help to define terminology and standard ideas that can be helpful.

There's nothing super remarkable about the patterns, the nicest thing is that they are ideas that are canonized and defined in ways that are repeatedly useful.

Kekoa
+2  A: 

I would say very

The trick with design patterns is learning where and when to use them. Then can do all sorts of things for you like:

  1. Make your code more readable
  2. Make it easy to maintain
  3. Make it more flexible
  4. And the list goes on...

But sometimes they can do the exact opposite of some of there benefits again its knowing how and when...

Have you ever tried to pull out a sliver with a framing hammer? You may love you framing hammer but its going to cause all sorts of problems if you try to use it that way...

I think that as you refactor you code it sometimes evolves into a particular pattern or you may have been using a pattern all along without realizing it.

J.13.L
In my experience, developers who consciously think about design patterns achieve the opposite effects far more often.
Michael Borgwardt
I would agree... I would say write the code... then refactor if possible and if necessary and like I said a design pattern may evolve. But sometimes during design you may see the opportunity to use one as well.
J.13.L
+12  A: 

Personally, I consider them vastly overhyped and of marginal value. The idea sounds great, but when you get down to it, there's really only a handful that common and useful enough to be worth remembering (and possible to remember).

I'd say their net effect is negative, due to the hideous overengineering perpetrated by people newly enamoured with the concept and trying to cram as many patterns into their code as possible. Perhaps even worse is the Maslow's hammer effect leading to bad design because instead of finding the optimal one, the developer remembered a design pattern that fits (badly).

Michael Borgwardt
Whether or not people exercise judgment or followership is orthogonal to whether design patterns are overhyped and of marginal value. The first rule of programming is: "Think." Whether some people replace that rule with "Use design patterns" is completely unrelated to the utility of design patterns when used in their proper place.
Justice
Justice, I am sorry, but you just don't seem to have run into the type of person that drinks the design pattern kool-aid, whose code has become your maintenance nightmare. Design patterns themselves may not be bad in the right hands, but like a questionable programming language feature, they invite abuse and are therefore suspect in and of themselves.
PeterAllenWebb
Not orthogonal - it's IMO exactly the hype (and the lure of the "neat idea") that causes people to substitute their case-by-case judgement with "use design patterns". And part of my point is that while the "proper use" of design patterns is beneficial, the benefit does not outweight the widespread abuse.
Michael Borgwardt
+1  A: 

Software Patterns are important whether you know you are using them or not... by definition.

A design pattern is simply a generalized, reusable solution to a commonly occurring problem.

You can either hack around until you re-invent the solution of every problem you encounter or you can learn the "patterns" that that programmers have been utilizing for generations. If you formalize your knowledge of most common, named patterns, you will have a common vocabulary to discuss and apply the solutions.

Enjoy,

Robert C. Cartaino

Robert Cartaino
+3  A: 

I find design patterns of marginal value. Any well-organized and designed software framework has hundreds of design patterns, and very few of them are described in the formal "pattern literature".

Before there were design patterns, there was well-designed software which had many patterns that could be re-used in many situations. For example, Kernighan and Richie's book on C contained an example of a calculator implemented using yacc and lex and a stack, symbol table, function pointer passing (i.e. basically dynamic binding) and contained a large number of patterns for the size of the book.

You can probably learn hundreds of more useful design patterns by studying e.g. Microsoft's .NET framework, Java class libraries, etc. than by reading a book on design patterns.

Really, good software has a design. And if the design is good, it can probably be re-used. Voila -- a design pattern.

Larry Watanabe
+1  A: 

I've seen too many cases of "Small Boy With A Pattern" syndrome. It usually strikes hardest just after a person has read the GoF book for the first time and instantly runs off to see how many of them they can fit into the project they're working on. (Extra points for cramming all 23 into a single project.) They end up with a system that's engineered within an inch of its life and impossible to understand or modify.

Eventually the fever breaks and they settle down enough to use them appropriately. But the damage can be great.

The cautionary tale is the "Core Java EE Patterns" book. It lists a bunch of stuff that addresses "best practices" for EJB 1.0 and 2.0 that are now considered anti-patterns. The EJB 3.0 spec does away with a lot of them. Spring is killing the rest.

Patterns have had their day in the sun, like UML. But the sun is going down on both. I don't think either one has saved the world or delivered on the hype.

duffymo
+2  A: 

While it can be useful to talk about design patterns sometimes, I tend to agree with those who consider them harmful in many situations.

The main argument I would make is that often they actually stop people from coming up with proper solutions to a specific problem. Instead of thinking about how to solve that particular problem, people try applying one design pattern after the other.

They also tend to hide language deficiencies. A lot of them are trivial in a language expressive enough. A prime example would be the Strategy pattern which is basically reinventing functional programming in a complicated fashion. Often people would be better off understanding the real programming principles instead of just talking pattern languages.

Having said that: I'd rather talk about patterns with someone than not having a common language at all. In that way they are important if there is no better option. If I can explain myself in more formal ways (e.g. algebras), then I stop caring about pattern languages. Of course some would claim I just invent my own pattern languages that way ;-)

Peter Becker
+2  A: 

I would say they definitely are important.

Among the typical reasons (shared vocabulary, not reinventing the wheel) they are a stepping stone to learning good software design. The majority of the design patterns out there start off by programmers with a good sense of OO principles applying what they know to solve a problem, and noticing that other people are coming up with the same solution. If you think of design patterns as a cookbook to solve the current problem you're stuck on, they're not really useful, and this is where you see the "design pattern hammer" come out and complicate designs.

If instead think of it as a window into good object oriented design you start to see how valuable they are, i.e. thinking in terms of the principles behind the design patterns instead of the specific design patterns themselves.

jls
A: 

Start with Principles before considering Patterns, because it's the overarching design principles that inform and motivate the emergence of patterns.

For your particular problem you are best served by following principles first and foremost. If you arrive at a well-known Pattern then, congratulations, you just re-discovered a Pattern, good for you. The problem is that it could take you a long time so it depends if you want to risk inventing a few anti-patterns along the way or whether you want a short-cut to something that's already been published. Consider it though, because you'll learn more than reading someone else's description of their own work.

The down-side (as many of the very good answers here have already pointed out) is that you could be tempted to apply a published Pattern in a context where it doesn't fit or just is not warranted.

A good place to start with Design Principles is by looking at Uncle Bob Martin's SOLID principles, the nice thing about them, once they sink in, is that you feel like you already knew them (which makes you feel smart) and

Uncle Bob's book Clean Code also covers alot of the same principles with some useful examples, only not so explicitly citing the principles as the original articles, focussing more on generally organising and tidying up your Functions, Classes, etc.

rohancragg
A: 

commented Design Patterns are helpful if you are trying to contribute to open source projects... enough said!

tranced_UT3