I'm beginning to wonder if the book Head First Design Patterns would be better titled Ass Backwards Design Patterns. Here are some quotes from pages 594 and 595 of this 629 page book:
First of all, when you design, solve things in the simplest way possible. Your goal should be simplicity, not "how can I apply a pattern to this problem." Don't feel like you aren't a sophisticated developer if you don't use a pattern to solve a problem. Other developers will appreciate and admire the simplicity of your design. That said, sometimes the best way to keep your design simple and flexible is to use a pattern.No one ever talks about when to remove a pattern. You'd think it was blasphemy! Nah, we're all adults here, we can take it. So when do you remove a pattern? When your system has become complex and the flexibility you planned for isn't needed. In other words, when a simpler solution without the pattern would be better.
Design patterns are powerful, and it's easy to see all kinds of ways they can be used in your current designs. Developers naturally love to create beautiful architectures that are ready to take on change from all directions.
Resist the temptation. If you have a practical need to support change in a design today, go ahead and employ a pattern to handle that change. However, if the reason is only hypothetical, don't add the pattern. It's only going to add complexity to your system, and you might never need it.
Filling 593 pages with rah-rah pattern talk, and then tacking this critical guidance on at the end of the book is downright irresponsible. This advice should be in 72 point blinking Comic Sans on the very first page.
Beginning developers never met a pattern or an object they didn't like. Encouraging them to experiment with patterns is like throwing gasoline on a fire. And yet that's exactly what this book does. Page 597 outlines how therapeutic it is for beginners to abuse patterns:
The beginner uses patterns everywhere. This is good. The beginner gets lots of experience with and practice using patterns. The beginner also thinks, "The more patterns I use, the better the design." The beginner will learn that this is not so, that all designs should be as simple as possible. Complexity and patterns should only be used where they are needed for practical extensibility.
Do you really want a junior developer using patterns everywhere? It's about as safe as encouraging them to "experiment" with a gas-powered chainsaw. The best way to learn to write simple code is to write simple code! Patterns, like all forms of compexity, should be avoided until they are absolutely necessary. That's the first thing beginners need to learn. Not the last thing.
The book isn't the only thing that's backwards: did you know the Head First girl pictured on the front of the book leads a shocking double life? That's right, student by day, stripper by night. Ok, maybe not ...
... but shocking nonetheless. Perhaps they're referring to the code smell of overcomplicated "explosion at the pattern factory" code this book encourages?
Posted by Jeff Atwood View blog reactions
« Hurricane Katrina Managed Code Analysis Tools »
I find it very funny that you criticize the book, but you link to its Amazon page using your affiliate ID.
Ervin on September 6, 2005 07:49 AM"Patterns, like all forms of compexity, should be avoided until they are absolutely necessary. That's the first thing beginners need to learn. Not the last thing."
Yeah. And beginner will know for sure, when the usage of the pattern is absoulutely necessary and when not. Especially if they never tried that pattern before.
I think Kathy and Bert know a big deal about beginners and teaching, so I am not exactly sure what the point of this post was.
I didn't say the book was entirely without merit. I like the writing style, and it's a good overview of patterns.
That said, I feel very strongly this advice -- that patterns are complexity, and not to be used lightly -- should be presented up front, not 600 pages in..
Jeff Atwood on September 6, 2005 11:21 AMI think that it is funny that the same picture is being used for both materials. You have to assume that both "companies" got it from the same box of clipart/pictures. With that said, I wonder if the girl even knows where and when her picture is going to be used. She was probably paid $100 for the original picture and could end up on everything from condom boxes to bran flakes.
matt on September 6, 2005 12:40 PMBan Comic Sans! [bancomicsans.com] It is an insult to centuries of typography. However, putting tags around that "font" is kind of fitting.
well, i'll offer up a good pattern book that likely isn't on the general radar:
Holub on Patterns: Learning Patterns by Looking at Code
for those not familiar, Allen Holub is an Olde Guy who got to java by way of C/C++ (yeah, not a .NET person). he hates beans and most uses of inheritance; on both points he is not alone, but most of the lemmings in the Apache crowd don't like him. feat not. this book has two (pretty much) complete, workable systems. one is a SQL interpreter. it is very dense going, but worth it.
robert on September 6, 2005 07:45 PMGosh, I think you're being a bit harsh. Presumably someone who picks up the book does so to learn about patterns. The book teaches them (in its own way), and then warns you at the end not to overuse them. If you don't get that far in the book, you probably gave up on learning patterns from it.
I enjoyed it, and went on to GOF from here.
Stick in the mud on September 12, 2005 06:13 PMHey at least they put that disclaimer in, even if it was near the last page.
I agree though. Newbies shouldn't be using design patterns in production code anyway. they should be trying it out in some test code first and refactoring production code where its obvious that the design pattern will help, hopefully with the guidance of a more senior developer.
Fregas on October 10, 2005 05:31 PMSo and where should a junior developer begin? The GoF book? Or simply saying, don't use patterns because it's too complex? I've never heard of somebody telling unexperienced developers how to learn about patterns, but I've heard dozen's of them how NOT to do it. Whow, the experienced users have spoken...
Reinout on October 11, 2005 03:28 PM> So and where should a junior developer begin? The GoF book?
Start with DRY and KISS, with a little YAGNI thrown in for good measure. Don't believe me? Read the quotes from Linus Torvalds and Anders Hejlsberg:
http://www.codinghorror.com/blog/archives/000113.html
Once you feel you've mastered the art of writing simple, straightforward code, then and only then should you advance to patterns.
Jeff Atwood on October 11, 2005 06:42 PM> So and where should a junior developer begin? The GoF book?
My vote is on The Pragmatic Programmer. That book is a short, very clear, easy to follow overview of most of the fundamentals. Followed up with HFDP it's about the most effective material I've seen for real-world software design.
Unfortunately by the time I got around to reading TPP, it was basically alot of "Hey, I do that!" moments with a few hidden gems. It could have saved me a lot of time a few years ago.
Eric Nicholson on August 4, 2006 06:19 AM> My vote is on The Pragmatic Programmer.
Yes, excellent recommendation. That, Code Complete, and Don't Make Me Think, would be the first books I'd recommend to a junior developer.
Jeff Atwood on August 4, 2006 09:14 AMI agree, junior developer armed with a pattern book is akin to a monkey with a hand grenade. At the very least, he'll blow up himself.
However, I am yet again suprised with the general perception of the complexity of patterns. For some reason, for most people pattern = complex. This is not true. Pattern is simply a solution for a particular problem that is known to work relatively well. The solution can be simple or complex, but the word "pattern" should not imply complexity per se.
Stas on August 5, 2006 02:12 AMI need some guidance. What exactly is programming? Is this regarding computer programming... or something a little, how shall I say, mindful programming.
Are you all robots?
Kaeli on October 8, 2006 07:20 PMOOP is a mess, and that is why it is hard to say anything solid about GOF design patterns. When, where, and why to use them is a can of worms. OOP is the modern-day GO TO. We need to borrow from Set Theory, not masses of object pointers. OOP should die, or at least shrink.
TomMinderson on November 12, 2006 09:37 AMWhy OOP is a mess? It's purpose really is reducing messiness by encapsulating code and attributes to meaningful little capsules called classes. Do you prefer global variables over class/object variables?
Of course, if you get some kind of API and it is full of undocumented classes that have unfamiliar names, you are lost and get bogged down. But in general there are reasons for going to OOP from spaghetti.
Don on November 12, 2006 11:55 AMcan anybody tell me two best design patterns?
mush mush on February 8, 2007 01:04 PMJeff, I'll have to agree with "stick in the mud" that perhaps you are, at least in tone, a bit harsh. I agree it would be a good idea to give some of their late advice a bit earlier. On the other hand, perhaps they felt that giving too many warnings too early would muddy the waters enough to scare "beginners" off, or, (gasp!) confuse them. People new to large-scale software development will be writing a lot of code - perhaps for the first time. That's why we hired them. I would say patterns are *not* complex - they encourage simplicity versus other horrible things people could/will do. We want the newbies writing lots of code to learn to use patterns.
Teaching about patterns in a decent, humorous way without scaring them off is probably a good idea. And winding up with some solid, practical advice is also a good idea, and a common pedagogical technique.
In the end, I think that people are more likely to actually read and understand this patterns book then many of the others out there. And that's the important thing!
Brian, I agree the presentation of the book is great. But I still think the advice may end up steering a lot of programmers in the wrong direction:
http://www.relevancellc.com/2007/5/17/design-patterns-are-code-smells
Jeff Atwood on May 22, 2007 09:32 AMA design pattern is just a tool. If it makes your job easier then use it (first you must know it exists) and if it doesn't, then don't.
Usually making our jobs easier means decreasing complexity. So patterns should be used only when they do that. So I don't agree that "patterns are complexity".
If you can take out that nail with your fingers don't be stupid and don't use a hammer. But if you can't use your fingers don't be stupid and use that hammer!!!
Daniel Cadenas on July 10, 2007 10:34 PMYeah, design patterns overuse can bring use in difficult situations, but not using them at all will create a big mess for sure.
oodesign on January 20, 2008 01:59 AM| Content (c) 2008 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved. |