13 ms·
Software Design Patterns Are Not Goals, They Are Tools
- prof_hobart 11y ago>, if you ever find yourself thinking, "I know, I'll use a design pattern" before writing any code, you're doing it wrong. Unless I'm misunderstanding him, I would disagree with this. When you're doing it wrong is when you use a design pattern without understanding what problem its solving, and whether you have that specific problem. To use his tool analogy - if you're a joiner who turns up to a job thinking "we always need to use a hammer" and start randomly hitting everything, then you've gone wrong. But equally, if you're halfway through knocking a nail in with your shoe and think "Oh look, I'm using the hammer pattern now", you're doing it just as wrong. If you're looking at two things you need to attach together and you've considered whether glue, a screw, a nail or something else is the most appropriate for this specific job, decide it's the nail and then think - "I need to use my hammer now", then you're doing it right.
- rtpg 11y agoI would say that using your shoe to emulate the hammer pattern is a good sign of flexibility and understanding the heart of the pattern. The point of the hammer pattern isn't the hammer, but the movements and the forces applied. In Europe hammers are an axiomatic part of their nails already so they don't even have a name for the hammer pattern! On the other hand, if you're with your screw and trying to spin it with the hammer because someone said use the hammer pattern...
- prof_hobart 11y agoIt's a good sign of flexibility, but not a good sign of being a professional on a job. And it's something I see depressingly often with programmers - tackling problems that there's a fairly well known existing pattern for, but not being aware of the pattern and either spending days/weeks rediscovering the pattern for themselves, or even worse inventing a new and less effective way of solving it.
- MoD411 11y ago"Software Design Patterns Are Not Goals, They Are Tools" - I do not understand why this needs to be said in the first place.
- UK-AL 11y agoI agree. It should be obvious. I don't know anyone who believes design patterns are the goals.
- ifeanyiisitor 11y agoUmm... he believed it, hence why he wrote about the insight he gained regarding this belief. And if he believed it, then there will no doubt be others like himself that believed it as well, and will benefit from this insight he has shared. Any insight like this that is shared with an intent to help others is valuable. It doesn't matter how simplistic or obvious we may think it is as there will be others out there that will learn from it. When we make statements like this, we discourage others from sharing things they have learn't in fear of being judged as not knowing something that should 'supposedly' be obvious.
- MyNameIsFred 11y agoWell, the author says that he had been an advocate and even educator on design patterns, yet also admitted that he has never read the definitive (GoF) work on the subject. IIRC, the book's preface declares the very thing the author "discovered" for himself and thought to share. If you started reading the book, and gave up after 2 minutes, you would still have learned this lesson. So, yes, it shouldn't have to be said.
- ifeanyiisitor 11y agoI'm inclined to believe that there are many that have not read the book and yet have tried to use the patterns mentioned in them. They would benefit from hearing what he has to say and why shouldn't they? Should they be punished for not reading the book by having all insights from one like them silenced? Have you also read every book that defines your craft? I don't think so. So wouldn't you then benefit from insight being shared that you missed because you did not read the book yourself? If the rule for sharing content was that you had to read every book on the matter first, then no one would be able to share anything. The point I'm simply making is that as long as there are those that will benefit from what you have to share, then its beneficial for you to share it regardless of how supposedly 'simplistic' or 'obvious' it is and mocking others for sharing things that we deem as obvious doesn't help anyone. Rather, it prevents others from learning. On the other hand, sharing something that is obvious to some but not to others, at least helps those that it wasn't obvious to. The guy did a good think by taking his time to collect his learnings and share it with others in the hope of helping someone else out there, only to be told that what he shared was obvious and so he shouldn't have said it. The price you pay for trying to help.
- dantheman 11y agoPatterns are from software archaeology, they were naming things that were commonly seen and what they were for -- they were helping build a vocabulary to talk about larger constructs. They are useful if you have a problem and one fits it perfectly, it can help you start thinking about it -- but it might not be a good fit. In general we should be keeping software as simple as possible, with the understanding that it can be changed and adapted as needed. Often large "pattern" based projects devolve into a morass of unneeded complexity to support a level of flexibility that was never required.
- mbrock 11y agoThey are rather from the interest of certain software developers in the work of the architect and philosopher Christopher Alexander, who saw patterns as the basic elements of a humane and sustainable style of building and communicating knowledge about building. The concept, like so many other concepts, drifted from its origin and became a more rigid and doctrinaire "system", especially after the misunderstood book by the "Gang of Four". In reality, patterns are everywhere in software, whether we call them that or not. Game loops, event servers, compilers, map/filter, microkernels, stdin transformers, for loops over arrays, etc etc etc. Richard P. Gabriel's book Patterns of Software is freely available and goes into the history and meaning of patterns. Alexander himself wrote a preface that's worth reading on its own.
- eru 11y agoAnd lots of these patterns can even become first class entities in the right languages. Eg almost all languages these days provide functions as a first class abstraction. You don't have to manage a call stack yourself.
- mbrock 11y agoMany, but not all, and the idea that nonreified patterns indicate a flawed language is pernicious. Gabriel's book talks about this.
- 11y ago
- userbinator 11y agoIt probably seems like an obvious statement to a lot of HN, but I have a feeling that it isn't to the majority of developers, who for some reason appear to love immense complexity and solving simple problems with complex solutions. I think a lot of them started with OO, which immediately raises their perception of what is "normal" complexity --- at that point, they're already creating more abstraction than is really necessary. Then they learn about design patterns and all the accompanying "hype" around them, so they think "awesome, something new and shiny to use in my code!" and start putting them in whenever they can, I guess because it feels productive to be creating lots of classes and methods and hooking everything together. It's easier to dogmatically apply design patterns and generate code mindlessly than to think about what the problem actually needs to solve it. The result is code that they think fulfills all the buzzwordy traits of "good software engineering practice" (robustness, maintainability, extensibility, scalability, understandability, etc.), but in reality is an overengineered brittle monstrosity that is only extensible in the specific ways thought of when it was first designed. That almost never turns out to be the case, so even more abstractions are added (including design patterns) on the next change, on the belief that it will help with the change after that, while leaving the existing useless ones in, and the system grows in complexity massively. I did not start with OO, I never read the GoF book, and don't really get the obsession with design patterns and everything surrounding them. I've surprised a lot of others who likely have, by showing them how simple the solutions to some problems can be. Perhaps it's the education of programmers that is to blame for this. The statement could be generalised to "software is not a goal, it is a tool". Related article: https://blog.codinghorror.com/head-first-design-patterns/ https://blog.codinghorror.com/head-first-design-patterns/
- TeMPOraL 11y ago> I did not start with OO, I never read the GoF book, and don't really get the obsession with design patterns and everything surrounding them. I've surprised a lot of others who likely have, by showing them how simple the solutions to some problems can be. Perhaps it's the education of programmers that is to blame for this. Design patterns are mostly crutches for languages that have pretty weak expressive power. In a powerful language, you don't need most of them. See also: http://norvig.com/design-patterns/design-patterns.pdf http://norvig.com/design-patterns/design-patterns.pdf, slides 9 and 10.
- bradenb 11y ago> In other words, if you ever find yourself thinking, "I know, I'll use a design pattern" before writing any code, you're doing it wrong. I completely disagree... if I'm working with a team. I've spent far too many hours trying to fix fragile code that comes about as a result of different devs with different methodologies trying to tie their code together.
- JustSomeNobody 11y agoI, too, disagree, but not strongly. Author used the adapter pattern in one of his examples. I think this pattern comes up more often when refactoring than when doing initial design. Not always (there are never any certainties), but usually. So, I think the warning should be more, be careful in what patterns you choose and it's ok, for now, to choose none.
- daigoba66 11y agoWhat you're describing sounds more like a teamwork problem - you're likely either missing someone with the "big picture" who is reviewing code, or a collaborative code review process.
- bradenb 11y agoI would agree that lacking either of those things would cause the problem I described, but in this case we have both of those. Most recently, I was the one joining a project after its incipient stage, so I was not the big picture guy, but the big picture guy chose not to establish any kind of patterns or standards so when others started joining the project--even with an understanding of how it should work--suddenly the app had a lot more functionality but it all performed terribly because of a lack of uniformity in design. Code review helps, but ultimately because there are no established patterns there is no justification for telling someone a task should be implemented differently, right? The only solution I can see is to establish that justification by trying to get the big picture guy on board with a massive refactor to establish some standards.
- dvhh 11y agoIsn't that what code conventions are for ? Additionally code review could fix that situation better.
- arxpoetica 11y agoJust now realizing there is ambiguity around the terms “design patterns.” Say it in a different crowd, they'll think you are talking about the kind of design patterns Brad Frost is writing about. http://atomicdesign.bradfrost.com/ http://atomicdesign.bradfrost.com/
- sageikosa 11y agoMaybe there's a common (patterned?) ambiguity to the idea of design patterns?
- golergka 11y agoI have been interviewing a lot of developers recently, and one of the best questions I've found is to ask them _why_ they have used MVC pattern in the test assignment (most do). Most of developers misunderstand the question at first and either start to explain how MVC works or explain how they would've implemented it without MVC (when you ask people why they did something, they often take it as "you shouldn't have done it"). But even when I clarify the question, a surprising number just can't even begin to answer it — instead they stumble and at best just tell that that's how they have always been taught to do it.
- sageikosa 11y agoThat you haven't been up-voted more affirms my belief that you are on the right track. If they can't explain why they don't know the value of it. If they don't know the value of it, they can't weigh that value against any others.
- projektfu 11y agoIs "it's the first thing that came to mind" an acceptable answer?
- sageikosa 11y agoThat's falls somewhere between "because its the way we do things around these parts" and "it's what we used on my last couple of projects". Perfectly fine for a certain degree of utility (maintenance, finishing, junior dev?), not quite so much for a lead, system designer or architect.
- GaveUp 11y agoI noticed the same thing when interviewing people. Answering why a decision was made would always trip people up, but it's far more revealing than any demo project can be. It doesn't matter, to me, whether the solution was right or wrong, but more the "why" that got you there and how it will get you to where you need to go. You can't problem solve effectively without understanding the reasons you're making the decisions you are. The same follows for patterns, I think. If you haven't thought about it critically and really done the work to understand the "why" (being told the "why" is not enough) you're going to struggle and mostly fail to implement it properly are in the appropriate situations.
- EliRivers 11y agoWhile we're here, SOLID is a nice acronym that is helpful as a checklist of generally good ideas to consider. It's not a law of physics, it's not compulsory, following it blindly can lead to worse outcomes and if transgressing it leads to a better outcome (with all things considered) then it should be transgressed.
- awinter-py 11y agodesign patterns are guru thinking. they're bad ways to describe self-descriptive tricks like callbacks. don't let a person who talks this way write docs ever; they'll focus on 'what's being used' rather than what's happening. design patterns are like when a consultant creates a stupid name for something that already exists -- the name isn't about expressive power, it's about declaring ownership so the consultant can sell the 'Consulting Method' to solve your problem. when a phenomenon or trick has an easily understood one-word name, don't let a nonexpert rename it to something nobody understands.
- jrochkind1 11y agoCallbacks only become self-descriptive or obvious once you've seen them a bunch of times. To a new programmer, say in javascript, who has never seen them before, they aren't at all self-descriptive or obvious. It is super helpful to have the term 'callback' to talk about them, and to understand what they are -- say, just a function you pass in that's then called back or whatever. Then you'll be able to recognize what it is when you see it in existing code/api, and how to use it, as well as when to use it when writing your own code/api. If you really just tossed someone at Javascript and they were a new programmer and had no idea what a 'callback' was, most people would have a lot more trouble figuring it out from themselves only from code examples, or would never think of using it themselves when writing code/api never having seen it before. That's all a "design pattern" is. "Callback function" is a common and successful design pattern in Javascript. (Less common or useful in some other languages, depending on the affordances of the platform). That's it. Yes, focusing on "what's being used" instead of "what's happening" is a problem, yes, thinking you can construct software just by robotically putting together "design patterns" is a problem. Design patterns are still a useful and inevitable part of software development, and recognizing that can make you much more efficient at learning how to write software, at designing comprehensible and maintainable software, and at reading other people's software.
- awinter-py 11y agoYes, I meant 'callback' is a better title than 'visitor pattern', not that callbacks are obvious without explanation.
- rhapsodic 11y agoA design pattern is a reusable solution to a recurring problem. Too many inexperienced devs forget that part, and use a pattern where the problem it's designed to solve doesn't exist. Had the author read the GoF book (he admits he still hasn't) he might have avoided that pitfall.
- joshdick 11y agoYeah, I can't believe someone would write a blog post about design patterns without reading the GoF book. The authors are very explicit in every chapter about what problems are a good fit for that design pattern.
- mirekrusin 11y agoHis problem may be learning about those concepts from snake-oil sellers - he mentions he didn't bother to read GoF and gets his knowledge from things like http://www.dofactory.com/products/net-design-pattern-framework http://www.dofactory.com/products/net-design-pattern-framewo... . My advice is to learn from people like Martin Fowler or Kent Beck and if you want to look at companies, look at something like ThoughWorks.
- johanneskanybal 11y ago"I didn't read the article or the comments but I think you're all wrong, maybe it's bad upbringing or maybe something else but whatever". ok thanks for sharing.
- emodendroket 11y agoAs far as I can tell design patterns are mostly about taking something simple and obvious and using terms to describe it that make it obscure and difficult to understand.
- davnicwil 11y agoCompletely accurate, in most cases. I think that's inevitable when you describe an abstraction with an analogy.
- gnaritas 11y agoPatterns are about giving developers a common vocabulary so they can discuss what they all do without having to go into insufferable detail each time. We all do lots of the same shit and it's extremely helpful to all use the same names for those things.
- emodendroket 11y agoWhy do I have to call it "the strategy pattern?" What was wrong with "passing in a function?" Giving it a name like that obscures the idea. Yes, I realize that if you don't have first-class functions you have to work around that with interfaces or similar, but now we're describing a workaround for a language limitation, which seems a bit less inspiring than what "design patterns" are sold as.
- maffydub 11y agoI think the word "strategy" encapsulates more about the semantics than "passing in a function". For example, the "visitor" pattern could also be described as "passing in a function", but there's a significant difference: a visitor is intended to be called on each element of a data structure in turn (i.e. a bit like an iterator callback), while a strategy defines an algorithm that you're expecting the caller to select at run-time (e.g. different cipher implementations). Syntactically, they may well be the same ("passing in a function") but semantically, they're very different. It can be useful to be able to have this shared vocabulary when talking about designs.
- badloginagain 11y agoDesign patterns, OOP, to a large degree programming languages are just tools. You don't hear of craftsmen saying things like "The only thing you really need is a hammer. It's been around longer than the other tools and you can use it on every project". Replace "hammer" with C or Java and you have a legitimate comment on a score of threads. > What patterns don't help with is the initial design of a system. In this phase, the only thing you should be worried about is how to faithfully and correctly implement the business rules and procedures. I submit that should be your overriding concern at all times, not just the design phase. If you have to refactor some code in order to extend it, tie it back to the changed requirement. This forces you to make the least amount of changes, refactoring the least amount code, breaking the least amount of unit tests and introducing the least amount of bugs into production.
- arthurvl 11y agoUnfortunately looking at just the business rules and procedures leaves the oft-hidden 'soft' requirements (the -ities) in the dust. Unless you explicitly state the corresponding requirements, having the business rules and procedures as your overriding concern will lead to pain. And explicitly stating a testable requirement for e.g. maintainability or security tends to be quite hard in practice.
- rootlocus 11y agoI found both his definition of the adapter pattern and his example to be a bit off. In his example, the adapter extends the external interface instead of the client interface. By definition the adapter must implement the client interface. It's even in the UML diagram displayed on the website he quotes (http://www.dofactory.com/net/adapter-design-pattern http://www.dofactory.com/net/adapter-design-pattern) > The fact was that I just didn't understand them the way I thought I did. > To be clear, I've never read the Gang of Four book these patterns are defined in After admitting he has a less than desired understanding of design patterns (proven by his poor example), he makes bold claims like: > if you ever find yourself thinking, "I know, I'll use a design pattern" before writing any code, you're doing it wrong. I'm having problems taking this article seriously.
- EGreg 11y agoGoals should include: 1) Solve the problem 2) Make it maintainable 3) Make it extensible 4) Make it scalable (server) 5) Optimize it for memory, speed So the reason to use an existing paradigm and a well-tested framework is because it makes the above easier, especially #2. And over time, #2 winds up saving you a lot resources and probably saves your project from tanking. Finally, using an existing well known platform also lets you hire developers who know what they're doing from the beginning, leading to more prosuctivity and less dependence on any one particular developer. We leverage the knowledge that's already out there.
- projektfu 11y agoWhen I was in college, I assumed (like most) that patterns were received wisdom in how to construct software. Then I actually attended a talk with John Vlissides and realized that patterns were an entirely different thing, closer to the "archaeological" sense dantheman mentioned. In this way, the study of design patterns correspond better to the study of rhetoric or poetics in human language. "Homeric Simile" could be a design pattern in poetry. In software, some rigidity of expression might be preferred, and so the design patterns also help us avoid creating new terminology for things that have been appropriately described. There are places where each pattern might have utility, and I suppose if there is any sense to the term "software architecture" it is in the ability to make sense of what the system should look like in a way that can be explained to the relevant parts of the team. There is a tendency, as well, among software developers to think that a complicated architecture must be the result of countless stupid decisions, probably made by junior technicians, who were doing things without understanding what's going on. Thus you find people exhorting others for simplicity, and acting like they've done their job at that point. But instead, complicated architecture is the result of compromises and rewrites throughout the software's life, and attempts to discard those old architectures and start afresh with similar tools usually result in an initially simplistic, but ultimately inflexible, design that will eventually evolve into a different complex architecture. The Linux kernel is an example of a complicated architecture that was designed from a standpoint of simplicity initially, and developed its own object-oriented layer on top of C, with pluggable elements all over, loadable modules, etc., and millions of lines of code. BSD is smaller and more coherent, but also much more limited in scope. There are also examples like Windows NT, which suffered from being the second system to 3 systems: Windows, OS/2 and VMS. In this kernel, there are so many design features that were included before implementation, that it seems incredible it was ever built. But they persisted and made it happen, and even eventually made it fast, in some cases by working around its design with new compromises and approaches. Still, it lacks the simplicity of a Plan9 or an Oberon, but what it doesn't lack is users. Anyhow, I digress. What is important to me about patterns is the language that we get from them, and the ability to recognize what's going on in code. They can provide useful hints about implementation gotchas, and they can also help people stop reinventing the wheel.
- apo 11y ago> Here's the problem I have with design patterns like these [Adapter Pattern]: they seem to be something that should occur organically rather than intentionally. We shouldn't directly target having any of these patterns in our code, but we should know what they are so that if we accidentally create one, we can better describe it to others. It's not clear what the author would have done differently in this example. It's one thing to raise concerns about pattern-first thinking in general, but quite another to spell out what exactly is wrong with reaching for the Adapter Pattern to solve a very specific problem under a given set of constraints. I can imagine a number of situations in which going straight for an Adapter is the only sane choice. I've come to view with great suspicion any general discussion of programming divorced from its context. Architecture Astronauts and Cowboy Coders can each do a lot of damage if left to their own devices.
- madeofpalk 11y agoI'm reminded of a set of tweets from Harry Roberts about whatever new hot CSS naming convention was popular for the week: > Modularity, DRY, SRP, etc. is never a goal, it’s a trait. Don’t let the pursuit of theory get in the way of actual productivity. > That’s not to say Modularity, DRY, SRP, etc. aren’t great ideas—they are!—but understand that they’re approaches and not achievements. There's nothing super revolutionary about these thoughts, but they've stuck in the back of my mind for a while now. https://twitter.com/csswizardry/status/539726989159301121?ref_src=twsrc%5Etfw https://twitter.com/csswizardry/status/539726989159301121?re...
- gwbas1c 11y agoDesign patterns aren't the problem. All a design pattern is, is a well-known way of doing something. When you build a house, do you re-invent how to frame, plumb, wire, and roof it? No. That's all a design pattern is. Choosing the right design pattern is akin to making sure that your basement is made out of cement and your walls framed with wood. (You don't want to put shingles on your countertops!) The problem is that some developers think they are some kind of magical panacea without really understanding why the pattern was established and what it tries to achieve. These are the over-complicated projects that everyone is complaining about in this thread. (These are the projects where the basement is made with wood or the concrete walls too thick; or the projects where someone decided to put shingles on the countertop.) I try to pick, establish, and follow design patterns in my code. It helps ensure that I don't spend a lot of time re-learning why some other technique is flawed; and it helps achieve a consistent style that everyone else on the team can work with.
- bjr- 11y agoRead the book. Then read the books that inspired the book.
- jrochkind1 11y agoYES. Design patterns are super useful as tools. As "goals" they are idiotic. I think lots of people that think they are idiotic have been exposed to them as "goals", or don't realize that's not the point. I think there is a larger issue here, which is that many kinds of software development, including web dev, has become enormously more complex in many ways than it was when many of us came up. People coming up now are looking for magic bullets and shortcuts and things they can just follow by rote -- because they are overwhelmed and don't know how to get to competence, let alone expertise, without these things. It's easy for us to look down on people doing this as just not very good developers -- and the idea of 'software bootcamp' doesn't help, I think it's probably not _possible_ to get to competence through such a process -- but too easy to forget that if we were starting from scratch now we ourselves would likely find it a lot more challenging than we did when we started. There's way more stuff to deal with now. "Design patterns" are never going to serve as such a magic bullet or thing you can follow by rote, and will often make things worse when used that way -- but so will any other potential magic bullet or thing you can follow by rote. Software doesn't work that way. It's still a craft.
- orasis 11y ago"People coming up now are looking for magic bullets and shortcuts and things they can just follow by rote" This is the normal progression of learning. As a beginner, following the rules by rote is the goal. So, for the newbie that is first being exposed to design patterns, implementing some of those patterns should be the goal so they can learn where they fit in the toolbelt.
- mirchiseth 11y agoFor another somewhat funny take on Design Patterns watch the first two minutes of this talk from last year DEVOXX https://www.youtube.com/watch?v=e4MT_OguDKg https://www.youtube.com/watch?v=e4MT_OguDKg Speaker echoes similar sentiments about design patterns being written by highly experienced developers and should be used to communicate about code etc.
- Arzh 11y agoThis article makes way more sense when he says he never read the Design Patterns book. If he had, he would know that before he started. They explain that the book is a collection of patterns that they have compiled from a bunch of people and from years of experience. The patterns did come about organically, and they were never meant to be the way to design software. They were only trying to come up with a common lexicon for something that they were all already doing.
- smoreilly 11y agoHow can someone doing research on these patterns not have read the most basic/important piece of literature on the subject?
- exception_e 11y agoKind of relevant to the discussions in this thread: https://en.wikipedia.org/wiki/Rule_of_three_(computer_programming) https://en.wikipedia.org/wiki/Rule_of_three_(computer_progra... When I do hit the magic 3 and can justify restructing code, I consider my options in terms of design patterns (which are very much tools!)
- id122015 11y agoI can say the same thing about programming. Thats why when I read HN I'm trying to understand what are you trying to achive. Something that goes beyond staying in front of the computer 10 hours a day.
- matchagaucho 11y agoStated in other terms, patterns are a means to an end. Not the end goal. Patterns will organically emerge as the result of ongoing refactoring.
- V-2 11y agoAs pointed out (arguably a bit harshly) in comments under the original article, this is really a strawman argument. That's because that ol' classical GoF book on design patterns - which the author admits has not even read - addresses this concern already. It's still a valid argument, but not exactly a fresh one. And speaking on the subject without even bothering to read the piece widely considered as canonical is a bit arrogant.
- olleicua 11y agoTHIS
- RangerScience 11y agoYES The point of design patterns is a way to describe what you've made succinctly. NO When you set out to do something that you don't yet know how to do, having a crank you can turn to get out functioning code is a good thing. I think what you mean is "Design Patterns are Tools, not Dogma". Plus, a lot of design patterns only make sense in typed and/or OOP languages, so under those circumstances, they can't be applied as goals.