139

I had a discussion with one of our senior developers who's been in the business for 20 years. He's pretty well known in Ontario for a blog he writes.

The strange thing is what he told me: he said that there is a piece of code that is a nightmare to work with because it was written from a textbook, and doesn't account for the real world. Adding a new field to the UI/database/Data layer takes 2-3 hours to do, whereas in his code it takes 30 minutes.

The other thing too is that he avoids design patterns because most programmers don't understand them and they are not good from a maintenance perspective.

Then there's also the idea that most web developers in Canada prefer to have their data model inherit from the Data Layer classes, rather than keeping it isolated. I asked him, "Isn't it industry standard for the model to be separated from the data layer?" He said sometimes, but most people here prefer not to do that because it's too much work.

It sounds like his reasoning for not coding using best practices is because it's a maintenance nightmare, few of our employees understand it (besides myself), and it's slow to work with if you need to push out new features or fields in a few days' time.

It's so strange hearing an opinion like this, considering that Stack Overflow mostly encourages people to follow industry standards. Is the problem that we are constantly forced to churn out new fields and features in a matter of days, that it's not possible to deduce a solid pattern that is flexible enough? That seems to be the gist of what I understand from this.

What do you make of these statements?

elixenide
  • 442
  • 1
  • 6
  • 17
Igneous01
  • 2,343
  • 2
  • 15
  • 18
  • 8
    Ironically, the Stack Exchange network is built on technologies and practices that probably favor your friend's approach. They use a lightweight micro-ORM called Dapper and avoid monolithic, layered architectures, for the same reasons that your friend cites. – Robert Harvey Aug 30 '16 at 19:45
  • 48
    ["The nice thing about standards is that you have so many to choose from..."](http://c2.com/cgi/wiki?AndrewTanenbaum) – Eric King Aug 30 '16 at 21:15
  • 70
    Personally I'm nervous of anything refered to as "best practice" (without justification) because it usually means "I don't know why this is a good idea but I want you to do it anyway; end of discussion" – Richard Tingle Aug 30 '16 at 21:31
  • 2
    Design patterns are good, components are better. There is at least one thesis (and probably others), backed up with actual code, about that topic alone: http://se.inf.ethz.ch/old/people/arnout/patterns 'HTH, – YSharp Aug 31 '16 at 05:24
  • 35
    industry standard , design pattern , and best practices are just terms for "Things that someone said work better on their context so it sohuld on yours too. probably. maybe"® . your senior dev's right. – CptEric Aug 31 '16 at 06:37
  • 86
    This has nothing to do with Agile. – Lightness Races in Orbit Aug 31 '16 at 08:53
  • 4
    Is not using Design Patterns a Design Pattern itself ? – Etsitpab Nioliv Aug 31 '16 at 09:26
  • 1
    @EtsitpabNioliv It's an Anti Design Pattern – TripeHound Aug 31 '16 at 11:02
  • 71
    "senior mvc developer" "design patterns are bad" the cognitive dissonance – Dan Aug 31 '16 at 11:44
  • 17
    About avoiding design patterns, there's two things I want to mention. 1) Design patterns were around forever long before anyone called them that -- they literally saw **patterns in the design** so they wanted to give them names to make them easier to discuss and communicate. 2) One should not strive to use design patterns, one should strive to use the best approach -- if the best approach is implementing a design pattern, so be it. It's possible this is what your friend meant by avoiding them. – Captain Man Aug 31 '16 at 14:11
  • 7
    MVC is a design pattern. MVVM too. Arguably IOC and dependency injection. In web stack you work "with" design patterns all the time, by using frameworks that are written around design patterns. But the need to sit down and write a factory (or whatever) from scratch does not come up that often, if at all. Now, back in the day when I was writing greenfield c++ for embedded and/or distributed applications, appropriately writing a design pattern from the ground up would come up twice a week... Ah, real programming, them were't days... ;-) – Grimm The Opiner Aug 31 '16 at 15:21
  • 7
    And here the reason why any person can end up working as software engineer. Because there's no enginee at all... We are software artisans... – Laiv Aug 31 '16 at 18:57
  • 8
    If he got hit by a bus, how long would it take for someone who is not him to add the next field? – Mr.Mindor Sep 01 '16 at 01:45
  • 2
    @DanPantry not so much, basics design patterns are ok, but more complex ones can be really though to understand for developers that will come after if they don't really understand it. I already try to use some nice design pattern, but others devs just didn't even want to understand it. – Walfrat Sep 01 '16 at 11:10
  • @Lightness: "Agile" in the "flexible" sense. – Robert Harvey Sep 01 '16 at 15:54
  • 3
    @EricKing similarly https://xkcd.com/927/ – Holloway Sep 01 '16 at 16:16
  • 2
    If programmers fail to understand standards, why would they understand something more random? – Jeroen Sep 02 '16 at 13:35
  • 1
    Whopping 30 minutes to add a field through the stack? Does that include Mr. Uppity blogging about it to the world, or just coding? – Kaz Sep 03 '16 at 02:08
  • If the practice from Canada, it must be right. We are computer geniuses. Proof: when a compiler runs on machine A, compiling a cross-compiler (perhaps itself) which targets machine B, but itself runs on machine C, that is called a **Canadian cross-compile**. https://en.wikipedia.org/wiki/Cross_compiler#Canadian_Cross – Kaz Sep 03 '16 at 02:11
  • 1
    ^ This is because "Canadian" is practically a synonym for "mind-blowingly clever" (at least in contexts in which the meaning is not already assigned to "smoulderingly sexy"). – Kaz Sep 03 '16 at 02:18
  • 1
    I think it has to do with personality type. I don't really use 'patterns' and I guess I've been doing it for 20 years. I'm an intuitive (N-type in MBTI), so I just have a natural feel for how things work. S-types (MBTI) are more process oriented so feel the need for concrete instructions. It's like the difference between cooking by taste and following a recipe. Some people need to follow an exact recipe, and some people just know what's good. I actually do use 'patterns', but I have no idea they have names or care to learn. I just think "oh, that way". – Chloe Sep 03 '16 at 17:56
  • 3
    "Avoiding design patterns" literally means "making my code as dissimilar as possible to everyone else's code". Now, if he was apathetic about design patterns (neither striving to use them, nor to avoid them) that would be different. – user253751 Sep 04 '16 at 12:09
  • 1
    While design patterns and agile methodologies are unrelated, your senior dev's frowning towards design patterns might be based on a misunderstanding. (The fact he's been there 20 years does not necessarily mean he *understands*. I've seen this myself elsewhere.) Design patterns are tools, like languages. How is it a tool's problem if the tool's *user* is *misusing* it? – code_dredd Sep 04 '16 at 16:13
  • An electrical engineer would laugh at the idea of best practice. He would ask you what the design and power and space budget is and the target unit price and performance,many then start designing. And I'm leery of any claim that 'most programmers don't understand XXX'. It is frequently claimed for example that arithmetic expressions should contain redundant parentheses 'because most programmers don't understand operator precedence'. I've never met such a programmer in 45 years and it is third-grade material. – user207421 Sep 06 '16 at 00:11
  • He could have been talking about the over-zealous, heavy-handed use of design patterns by people who just learned about them. One warning sign of this is when the name of a design pattern shows up in the code. For example, a class named `SomethingFacade` should set off alarm bells. – Kevin Krumwiede Sep 06 '16 at 06:47
  • @KevinKrumwiede if I'm using a factory + strategy combo for supporting file extensions, it would make sense to call the classes FileFactory and XMLStrategy, CSVStrategy, ExcelStrategy than anything else - that seems clear what the code is trying to do. – Igneous01 Sep 06 '16 at 18:54
  • 1
    @Igneous01 Good point. There are certainly exceptions. – Kevin Krumwiede Sep 06 '16 at 18:58
  • @DanPantry: That's because you equate "Senior Developer" with "knows moar patterns." – Robert Harvey Sep 06 '16 at 19:13
  • 1
    @RobertHarvey That would make sense if you ignored the letters "mvc" in between "senior" and "developer. MVC is a pattern. 62 other people made that connection.. – Dan Sep 06 '16 at 19:17
  • Or, they just liked your comment. – Robert Harvey Sep 06 '16 at 19:27

13 Answers13

244

These are the words of someone who has found success and ignores people that try to tell him what to do in pattern jargon that he doesn't understand.

Design patterns and best practices are not the same thing. Some people think they are and drive people who know what they're doing nuts. Even if they don't know the proper name for what they are doing.

Design patterns existed before they had names. We gave them names to make talking about them easier. A pattern having a name doesn't make it a good thing. It makes it a recognizable thing.

This guy is likely using patterns neither one of you ever heard of. That's fine, until you need to talk to him about how something is done. He's either going to have to learn how to talk to you or you're going to have to learn how to talk to him. Has nothing to do with who is "right."

candied_orange
  • 102,279
  • 24
  • 197
  • 315
  • 13
    Agreed, with the caveat that, when most people use the term "design patterns" nowadays, they're usually referring to the [Gang of Four](https://www.pearsonhighered.com/assets/bigcovers/0/2/0/1/0201633612.jpg). – Robert Harvey Aug 30 '16 at 19:39
  • 1
    I'm sure he is using design patterns that make sense to him and the rest of the team, but they're not your standard (factory, strategy, command, etc...) ones. More like very elastic classes and behaviour that are easy to stretch or compress. I personally like using the GoF patterns because they make code so easy to understand from a big picture perspective, and are pretty flexible as well. – Igneous01 Aug 30 '16 at 20:05
  • 35
    Right and I like using English, it makes sense to me. Don't know why it's taking French people so long to adopt it. Till they do I'm going to learn a bit about this metric system I keep hearing about. – candied_orange Aug 30 '16 at 21:00
  • 6
    It might not be that he doesn't understand, it might also be that he does understand but he knows that not everything applies in all situations. – whatsisname Aug 30 '16 at 21:15
  • 150
    _"A pattern having a name doesn't make it a good thing. It makes it a recognizable thing."_ Oh my god this is the best summary of the problem I've ever heard :D – Lightness Races in Orbit Aug 31 '16 at 08:53
  • 4
    What drives me nuts is all those people talking about *anti-patterns* when they just mean bad practices (that often have nothing to do with design patterns) – Jan Doggen Aug 31 '16 at 13:21
  • 5
    When you talk about an anti-pattern you're obligated to talk about more than the pattern, but also the bad practice. Claiming chopsticks are evil is meaningless even if you define exactly what chopsticks are, which is all a pattern is about. You need to explain what a fork is. Or that pizza is a finger food. Saying "chopsticks are an anti pattern" simply doesn't say enough to mean anything. – candied_orange Aug 31 '16 at 14:00
  • 7
    @JanDoggen They're called (anti-)patterns because they are also common patterns in software development (some of which are design-related patterns). – JAB Aug 31 '16 at 17:20
  • @LightnessRacesinOrbit adding someting like `that is used to handle a recognizable problem` would have been perfect :) – Walfrat Sep 01 '16 at 11:12
  • 3
    @CandiedOrange: To be fair, English uses metric too. It's just your wild offshoot variant that doesn't ;) – Lightness Races in Orbit Sep 01 '16 at 11:33
  • 2
    @LightnessRacesinOrbit It is a good quote to help move people away from pattern obsession, but my understanding is that the use of "pattern" in GoF came from the idea of a "[pattern language](https://en.wikipedia.org/wiki/Pattern_language)", in which a pattern is specifically a *good* thing (the best known way of solving a specific problem), rather than just a recurring thing (as the word "pattern" literally means without context). – Ben Aaronson Sep 01 '16 at 14:59
  • @BenAaronson: Possibly so, but times have changed :) – Lightness Races in Orbit Sep 01 '16 at 15:48
  • @LightnessRacesinOrbit I agree, the focus on patterns never really made much sense to me – Ben Aaronson Sep 01 '16 at 16:27
  • 5
    Remember the [GoF show trial](http://c2.com/cgi/wiki?ShowTrialOfTheGangOfFour) before you go claiming any pattern is good in every context. The issue isn't so much pattern obsession as crutch obsession. Learning patterns, frameworks, or paradigms is good. Using them as a crutch is not. There just aren't any easy answers. Stop pretending there are. Take responsibility for writing code appropriate to your real needs. There is no skill you can learn here that will provide an excuse to turn off your brain. – candied_orange Sep 01 '16 at 16:31
96

Many design patterns, of the kind that you and your friend are describing, are really just workarounds for deficiencies in programming languages. Use a more expressive programming language, and most of the need for these design patterns disappears.

Because good design patterns are required to cater to many possible usage scenarios, they tend to be over-engineered. Over-engineered code has a cost: you have to read it, understand what it does, and understand how it works within the context of the entire software system. Consequently, as with any other software development technique, you have to evaluate the technique against the cost of using the technique, and decide if the benefits exceed the cost.

All other things being equal, less code is always better. I've been through layered architectures where you literally have to make three to six hops through multiple projects to find any code that is interesting, which is to say, code that actually accomplishes something other than adding overhead.

Well-known software patterns are supposed to give you a common vocabulary by which you can communicate design strategies. Unfortunately, many software developers don't understand the software pattern vocabulary well enough to properly apply it to their programming problems. Inexperienced developers see these patterns as being within the domain of experts; they want to be seen as experts, and so they try to learn and apply the patterns too early, before they are ready. What they really should do instead is focus on learning the fundamentals of programming first, and then attempt to solve the problem that each pattern solves themselves. If they do this, they will be in a much better position to understand and apply the patterns correctly.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
  • 4
    I guess I just feel a little shocked, considering what I was taught and told by some profs and others that showed me ways of applying techniques to common problems. I'm not a fan of spaghetti code or 1000 line functions (even if they are easy to change and maintain) which is what a lot of our current software looks like. Some controller methods are absolutely ridiculous in how much they are trying to do all at once. – Igneous01 Aug 30 '16 at 20:18
  • 19
    Well, that's a different problem than the one you're describing in your question. The shop I work at now is living proof that you can be agile and still have very clean, lean code that is easy to maintain, but it is not the usual enterprise, multi-layered stuff you see in most Java shops, and it's fairly "non-standard" in its approach. We don't have a year to build apps the "enterprise" way. – Robert Harvey Aug 30 '16 at 20:21
  • 2
    It's a trade off - on the one hand you can quickly add new features and tidbits in little time - the downside is that all of this happens in 2-3 methods in particular. It gives me the impression that this 'bad' code is actually 'good' for the business, even though I was told otherwise. – Igneous01 Aug 30 '16 at 20:24
  • 2
    Use different languages and you have to use different patterns. Each language and each paradigm has it's patterns. Its just that they are much rarely talked about than OOP patterns and that OOP-hating people tend to vehemently fight for not calling patterns "patterns". – Euphoric Aug 30 '16 at 20:41
  • 34
    @Igneous01: Note that what a professor who has never had any real-world experience considers "good" could vary radically from what a business trying to make money considers "good." – Robert Harvey Aug 30 '16 at 20:58
  • 8
    "Unfortunately, many software developers don't understand the software pattern vocabulary well enough to properly apply it to their programming problems." This is me in a nutshell. =) The few I have seen the names of, I have an *extremely* difficult time spotting a real implementation of them. I probably have blocks of code I've written that could be classified as implementing patterns, but I sure couldn't tell you which ones. I've come to think that the patterns are much less important than the code actually being decipherable and requirements changes only affecting a few places of code. – jpmc26 Aug 31 '16 at 01:54
  • 3
    Also, your comment about "the 'enterprise' way" reminded me of [this](http://thedailywtf.com/articles/Bitten_by_the_Enterprise_Bug). (I'm sure you've seen it; you might even be referencing it. But for those who haven't.) – jpmc26 Aug 31 '16 at 01:58
  • 35
    While I'll pedantically take issue with "less code is always better" because I know it leads to code that looks like [brainfuck](https://en.wikipedia.org/wiki/Brainfuck), I will enthusiasicly agree with the "pattern vacabulary" point. Don't complain that my code is crap just because you can't find it in your textbook. There are plenty of perfectly good reasons to call my code crap, but that isn't one of them. – candied_orange Aug 31 '16 at 02:04
  • 1
    Upvoted for first voted comment. So often, people espouse "design patterns" (quotes are necessary because the term is so hard to define in the first place) as ways to fix problematic code, without taking a step back to consider the root problem -- which is often the language itself. – gardenhead Aug 31 '16 at 03:26
  • 23
    "code that actually accomplishes something other than adding overhead" -- I thought the goal of enterprise software was that *there should be no code that actually accomplishes anything*. Any actual behaviour that the software might have, should either be an emergent property of the layered design, or else should be table-driven from business rules that the code treats as data. I'm only 50% joking. – Steve Jessop Aug 31 '16 at 08:32
  • 6
    I don't agree at all that "design patterns ... are just workarounds for deficiencies in programming languages". If your language has built in support for "$foo is an observer of $bar", that's great - *implementing* the Observer pattern is now really easy! But you're still using the pattern to *design* your code. If your language doesn't require you to design anything, then we're all out of jobs... – IMSoP Aug 31 '16 at 11:53
  • 6
    @CandiedOrange less code = "don't do unnessesarry stuff", not "obfuscate your code". To reference some recent work I was code reviewing, a 30 line function to parse some text had been written, where the better approach was 3 lines using a simple regex search (simple being "word.*word") which was less code and far more readable. – Baldrickk Aug 31 '16 at 12:01
  • 3
    I disagree about "less code is always better". It's often better, but if you find yourself trotting out an absolute like that, it's generally an indication that you're making an overbroad statement. – Jeremy Holovacs Aug 31 '16 at 20:04
  • 5
    @JeremyHolovacs: "All other things being equal." – Robert Harvey Aug 31 '16 at 20:05
  • 2
    @RobertHarvey what if more code is more descriptive, or more intuitively understood? I may be being nitpicky, but IMO functionality/ efficiency is only one metric of quality code, and sometimes, less is not more. – Jeremy Holovacs Aug 31 '16 at 20:08
  • 5
    @JeremyHolovacs: Then it's not "all other things being equal," is it? Mounds of code that don't perform any useful function or add any value are neither necessary, more descriptive or more intuitively understood. – Robert Harvey Aug 31 '16 at 20:10
  • 2
    @RobertHarvey Isn't it? If everything else is the same, but you can write the code short or verbose, isn't that "everything else being equal?" I recognize I'm being pedantic to a degree, but there are considerations outside quantitative, equatable concerns. Your statement sounded like a philosophy presented as undeniable fact. – Jeremy Holovacs Aug 31 '16 at 20:18
  • 4
    @JeremyHolovacs: Then just pretend it isn't an absolute. If I can do in 10 lines of code what someone else did in 100 without negatively affecting functionality, clarity, performance or maintainability, I'd say that is *always* a win. – Robert Harvey Aug 31 '16 at 21:05
  • IMHO sometimes "less code" can lead to "clever code", so I guess there is a limit of how much "less of a code" is healthy to a codebase. – Luis Vasconcellos Sep 05 '16 at 16:14
  • @LuisVasconcellos: That would be the "maintainability" vector, which I mentioned earlier. – Robert Harvey Sep 05 '16 at 19:39
  • Surprised these weren't already linked here: ["Design Patterns" Aren't](http://perl.plover.com/yak/design/) and [Ralph Johnson on Design Patterns of 1972](http://blog.plover.com/prog/johnson.html). – jrw32982 Sep 07 '16 at 03:25
86

Stackoverflow.SE and Programmers.SE mostly encourage people to follow best practices like SOLID, not industry standards. And believe it or not, the de facto industry standard is often the "big ball of mud" architecture - seriously.

But to answer your question directly: the problem with design patterns is a similar one as with inheritance - lots of mediocre devs overuse them, which has a certain risk of creating overengineered, hard to maintain code. But the answer to this is surely not to avoid or forbid the use of design patterns (or inheritance) completely, the answer is learning to use these tools in situations where they make sense, and only there. And this is fully independent from working "agile" or not.

Doc Brown
  • 199,015
  • 33
  • 367
  • 565
  • I think the specificity of your statement "the problem with design patterns is a similar one as with inheritance - lots of mediocre devs overuse them" is unnecessary... with all aspects of coding, a developer not educated in the proper use of something may and often will misuse it, and write sub-optimal code. This could be considered an axiom of development in general. – Jeremy Holovacs Sep 06 '16 at 14:49
  • 1
    @JeremyHolovacs: not exactly. The problem I see is that even educated developers overuse them. I have seen too often solutions where experienced devs tried to shoehorn a problem into a pattern which did "somehow" fit, but not well. – Doc Brown Sep 08 '16 at 05:47
45
  1. Design patterns are just names used to communicate ideas. I often found myself doing things which later I found that have a name. Thus, there is no "design pattern way" as opposed to a "non-design pattern way".

  2. Design patterns are guidelines. As everything, each of them has advantages and disadvantages. The key is not to learn the pattern and apply it where it fits but rather to understand the idea of the pattern, the advantages and disadvantages it has and use it to get inspiration for the solution to your problem.

  3. Every best practice and guideline can be ignored if there is a good enough reason. Valid reasons include development time and expectations from the application. For example, I'm aware that it's bad to hardcode values (stupid example) but for a proof of concept, the advantages might outweigh the costs (in this case, mostly development time). However, if a decision like this is made, it might backfire and at some point a refactoring might be required.

Paul92
  • 2,571
  • 15
  • 17
30

To add another metaphor to the soup, design patterns are Clippy the Microsoft Office helper. "You seem to be doing the same thing to a whole bunch of stuff. Can I help you with that by offering you Iterator or Visitor?"

A good write-up of those patterns will indicate when it's useful to do something the same way it's been done many times before, what mistakes you'll make the first time you try it, and what common ways have been found to avoid those mistakes. So you read the design pattern (or review it from memory) and then you get on with your work. What you can't do, is get by only using Clippy and wizards.

Where inexperienced people can go wrong and write code that doesn't take account of reality, is when they think their list of design patterns is a complete list of all possible approaches to solving problems in software, and try to design code by linking together design patterns until it's finished. Another poor tactic observed in the wild is to shoe-horn a design pattern into a situation it's not really suited for, on the basis that the design pattern "is best practice". No, it may or may not be best practice for the class of problem it actually solves, but it is certainly not best practice for problems that it fails to solve, or for problems that it solves only by introducing needless complexity when there's a simpler solution.

Of course it's also possible for someone to avoid a pattern on the basis that YAGNI, then realise they do need it and grope towards the normal solution. This is usually (but not always) worse than realising the requirement from the beginning, and is why even in agile development it's frustrating when totally predictable requirements aren't discovered early. I cannot have been the only C++ programmer who was highly amused that Java initially rejected generic containers as needlessly complex, then bolted them back on later.

So it's almost certainly a mistake to avoid writing an Iterator on principle because you prefer to avoid design patterns.

Adding a new field to the UI/database/Data layer takes 2-3 hours to do, where as in his code it takes 30 minutes.

You can't really argue with that: by this metric his design is far better than the other one. Whether that's because he avoided design patterns is questionable though, I think it's more likely because he considered the right "real-world" issues when designing it, and with the benefit of experience is better at his job than someone armed only with a textbook and high ideals.

So he recognised that any pattern which requires you to touch a lot of different points in the code to add a field is a bad pattern for the job, "make it easy to add fields", and he didn't use those patterns. Layered architectures indeed can suffer in that respect, and it is wrong to use design patterns without appreciating their disadvantages.

As against that, how long does it take to write a new UI in his design, and how long does it take in a layered architecture? If the project called for him to constantly build and deploy new UIs over a fixed data model, instead of constantly adding fields, hopefully he'd have designed for that instead. Or as well. But for all its benefits, saying "we're doing agile" sadly does not mean you'll never have to make another trade-off!

Selecting from a menu of design patterns certainly can stop you thinking about the most important concerns. But recognising when you're writing a Visitor, and documenting or naming it "Visitor" to help readers get it quickly, doesn't much get in the way of anything. Writing "this is a Visitor" instead of documenting it properly is a terrible mistake for the reason your senior dev gives -- programmers won't understand it. Even programmers who know what a Visitor is need more information than just, "this is a Visitor".

Steve Jessop
  • 5,051
  • 20
  • 23
  • 5
    "design patterns are Clippy the Microsoft Office helper" I'm going to have nightmares tonight. – MetalMikester Sep 01 '16 at 11:40
  • "Where inexperienced people can go wrong [is when they] try to design code by linking together design patterns until it's finished." Hear hear. I wish I had multiple upvotes to give. :) – Quuxplusone Sep 04 '16 at 18:37
  • I also wish I had multiple upvotes for the final paragraph. Design patterns are the *vocabulary* of programming: you'll be a better *and clearer* writer if you have a large vocabulary. I can tell a *Factory* from a *Builder* when I see them, but I didn't get that from reading books on design patterns, any more than I learned how to tell a *crag* from a *bluff* by reading an English dictionary. – Quuxplusone Sep 04 '16 at 18:38
20

Your colleague seems to suffer from the NIH syndrome ("Not Invented Here").

It's perfectly plausible that his code makes it easier to add new fields: I'm also much faster to update my own code than the code written by other guys. But this short-term speed doesn't say anything about the maintainability and portability of the code. I'll give him the benefit of the doubt: The existing code might indeed be badly structured if it has followed a textbook badly or followed a good recipe in the wrong context.

Avoiding design patterns is really surprising. In my last 30 years of coding and managing coders, design patterns helped to put words on things that were done instinctively, helping so to understand more quickly the intent, the advantages, inconveniences, risk, opportunities and related patterns. Design patterns proved to be real accelerators for mastering complexity!

  • Perhaps your colleague is really much more intelligent than most of us and he can afford the overhead of reinventing patterns without noticeable productivity decrease?

  • The arguments that "programmers don't understand design patterns" sounds like "I can't really explain what I'm doing". Or "I don't want to argue about my own design". I really think that patternization could leverage overall understanding, and it could allow less senior colleagues to share valuable opinions. But maybe your senior colleague wants to avoid just that.

Layered approaches have proven to be superior to other architectures in most enterprise applications. World-class leading packages are structured around this idea and outperform artisanal architectures by orders of magnitude. Martin Fowler presents this approach in his excellent book on "Patterns of enterprise architecture". Oh! Sorry again: It's about proven patterns; no chance in your colleague's NIH view ;-)

Matthew Flynn
  • 13,345
  • 2
  • 38
  • 57
Christophe
  • 74,672
  • 10
  • 115
  • 187
  • NIH syndrome, interesting, I had not heard of this before. Evidently that is the issue that most North American employers are facing with how to manage their employees! – pay Sep 01 '16 at 20:38
  • @pay I'm not sure that this is limited to North America ;-) It's always tempting to go for solutions that we already used in the past with some success. It's the comfort zone. But one should always remain open to new ideas and constructive dialogue with challenging colleagues. After all, "*You travel faster alone, but farther together.*" – Christophe Sep 01 '16 at 21:37
16

A key insight many people miss is that software design is contextual. It exists to reach business goals, and different goals may require different approaches. Put differently, there is no design that is always best, even though there is always a best design.

Design patterns are standard solutions to standard problems. However, if you do not have the problem, solving it is a waste of effort.

The key difference between waterfall and agile software design is when design decisions are made. In waterfall, we gather all requirements, identify which design patterns we need, and only then start coding. In agile architecture, we follow the YAGNI pricinple to defer design decisions until the last responsible moment, when we know as much about the choice as we possibly can.

That is, in waterfall, design patterns tend to be applied if their need is anticipated, in agile, when they are actually needed. As a consequence, agile projects tends to apply design patterns less often, because not all anticipated needs are actual.

meriton
  • 4,022
  • 17
  • 18
  • 1
    +1 for `Design patterns are standard solutions to standard problems`. I'm a bit disapointed to not saw that in more upvoted answers. This so require first to identify if your problem you're wokring on match to a standard problem, and really often, they will aniway. – Walfrat Sep 01 '16 at 11:06
8

Design patterns aren't really called design patterns because they prescribe what to do. Design patterns are design patterns because they describe what has been done before. Some developer or developers designed a method that accomplished a particular task well, and were able to apply it to similar situations with similar results. That's all it is. Many patterns have inherent strengths and weaknesses, and it is up to the educated developer to evaluate the technological and business needs to determine an appropriate pattern to apply.

In that light, unless you are truly committed to writing 100% one-off code, where no concepts or implementations are usable from one use case to the next, you are almost certainly using at least some design patterns. They may not have flashy, common names like "Repository" or "Unit of Work" or even "MVC", but that doesn't make them "not a design pattern".

Jeremy Holovacs
  • 221
  • 1
  • 3
6

I usually like to think of it in the way of - say - "navigation" using the GPS. When learning 'best practices' and 'design patterns' - you learn to take the GPS navigation route. But when you know the area, you'll often learn that driving down a side road will lead you past problem areas, get you there faster and/or better. It's much the same when it comes to these things - experience makes you able to deconstruct your toolbox and take short-cuts.

Learning design patterns and learning "best practices" means you gain an understanding about the idea behind so you can choose in a given situation. Because real life situations are often more complex compared to theoretical situations - you will often have constraints and issues not found in the textbooks. Clients/Customers want their product fast and usually cheap; You need to work with legacy code; You need to interact with third party tools which may very well be black boxes and ineffective; and all sorts of things. Your situation is specific - best practices and patterns are more general.

One major reason that many people on sites like SE will give you 'best practice' answers and 'design pattern' answers is that because they're answering in a general and abstracted solutions and thereby it helps provide a common language for solving a type of problems. And to get you to learn.

So - no - design patterns are not frowned upon in Agile development environments; development however is rarely general and abstract enough to fit a pattern perfectly and the (experienced) developer knows this.

5

Adding a new field to the UI/database/Data layer takes 2-3 hours to do, where as in his code it takes 30 minutes.

If you want to "optimize" a design you need to say what you're trying to optimize.

For example, a racing bicycle is an optimized vehicle ... and a Boeing 747 is also an optimized vehicle ... but they're optimized for a different set of requirements.

The idea of the "MVC" pattern, for example, optimizes for things like:

  • Different views of the same model (view is independent of model)
  • Each layer can be developed separately (e.g. by different teams) and tested separately (unit tests) before integration
  • etc.

Whereas his code might be optimizing for something else, for example:

  • Minimal lines of code
  • Easy for one person to make a change which affects all layers (by not having really distinct layers at all)
  • etc.

Pattern descriptions start with a description of the problem which pattern is intended to solve. If he thinks it's "best practice" not to use a specific pattern, then (assuming it's not a stupid pattern, assuming it's a pattern which is useful sometimes) I suppose that he doesn't have/experience the specific problem which that pattern claims to solve, and/or he has got a different (bigger or more urgent, competing) problem which he's trying to optimize for instead.

ChrisW
  • 3,387
  • 2
  • 20
  • 27
  • "by not having really distinct layers at all" -- or, to be fair, by having acceptable "default behaviour" that propagates through the layers. For example, web-based SQL admin apps are a presentation layer that automatically updates itself when the database layer changes. It's just that, other than for limited uses, they don't actually present your data the way you want it presented to users :-) Half an hour seems incredibly quick to add a new field, suggesting that there's no significant UI to design in connection with the new field, layered or otherwise. – Steve Jessop Sep 05 '16 at 08:57
4

Design patterns are tools. Like tools, there's two ways to use them: the correct way, and the incorrect way. For example, if I give you a screwdriver and a nail, and ask you to join two pieces of wood together, you should ask me for a hammer. Hammers are used for nails, while screwdrivers are used for screws.

Too often, a design pattern is advertised as the One True Way, which is often only true when particular problems arise. Junior developers are often like children when they find something new to play with; they want to apply that design pattern to everything. And there's nothing inherently wrong with it, so long as they eventually learn that Pattern A applies to Problem B, and Pattern C applies to Problem D. Just as you don't use a screwdriver to drive nails, you don't use a particular pattern just because it exists; you use the pattern because it's the best (known) tool for the job.

The flip side of patterns are anti-patterns. Things that have proven time and again to be bad, usually in terms of execution time or memory. However, both patterns and anti-patterns do no good to the developer that doesn't understand why they exist. Developers like to think that what they're doing is new and inventive, but most of the time, they're not. It's likely been thought of before. People before them have created the patterns because of experience.

Of course, junior developers often seem to come up with new ways of doing old things, and sometimes those ways are better. However, too often it ends up being a case of the Dunning-Kruger effect; the developer knows just enough to make a functional program, but doesn't understand their own limitations. The only way to get past this seems to be through experience, both positive and negative. They ignore patterns because they believe themselves to be superior, but don't know that, in reality, 10,000 developers have already used a specific design, and then discarded it because it was actually bad.

Agile favors "getting things done responsively" in regards to rapidly adjusting to evolving client needs. It neither favors design patterns nor despises them. If a pattern is the fastest, most reliable method, then the developer should use it. If a particular pattern would cost more time than simply "getting it done," using something that's not-a-pattern is likely okay (assuming, of course, that performance isn't severely degraded, etc). If no known pattern can be found, designing their own is preferred over telling a client "no." Clients, especially paying clients, are usually right.

Anyone who claims that patterns are The Way, or claims that patterns are The Bane Of Existence, are wrong. Patterns are tools, meant to be applied to specific situations, and have varying degrees of success based on circumstances. This is a Truth, one that doesn't depend on if you chose MVC or not, if you use Data Transfer Objects, or not, etc. What matters is implementing code in a reasonably short time frame, that performs reasonably well for users, and is reasonably free of logic bugs.

Usually, patterns will allow a coherent form of design, and will perform better than ignoring all patterns in favor of writing 100% original ideas, but you can't avoid all patterns. For example, if y = x + 5, are you really going to write y = x + (5 * 3 + 15 / 3) / 4, just to avoid the pattern of writing x + 5? No. You're not. You're going to write y = x + 5, and move on to the next problem.

People use patterns every day, and that's okay. What matters the most is having code that's logically functional, rarely crashes, and is user-friendly. Nothing else matters more than that.

phyrfox
  • 529
  • 3
  • 6
  • I think the caveat with this are situations that, based on your 'current' understanding of the problem and domain, you can create a new class or follow a pattern that applies to the situation, but then the next day a client wishes for you to make customizations for them to some small facet that other clients will not want in their version. Consolidating a codebase that caters to the needs of 2 dozen clients and avoids copy pasta seems impossible to accomplish. I just ran into this today when refactoring an old mail merge process. – Igneous01 Sep 01 '16 at 16:15
2

You can't 'avoid design patterns', except I guess by avoiding designing any two parts of your system the same way (which I don't recommend and I doubt your senior developer is doing). What he probably means is 'avoid blindly using a design just because it adheres to a design pattern'. Thinking about what you're doing is definitely a 'best practice', and one universities ought to exist to teach; sadly, that doesn't seem to be happening.

Jonathan Cast
  • 217
  • 3
  • 10
2

Design patterns are not antithetical to agile practices. What is antithetical to agile practices is using design patterns for the sake of using design patterns, the common practice among fresh graduates and students to think along the lines of "how are we going to solve this problem using a factory pattern".

Agile means choosing the best tool for the job, NOT trying to shape the job to fit the tool you've selected.
And tbh that's what ALL common sense development practices come down to (though often you of course have to make compromises because the selection of tools you can choose from is usually restricted by corporate standards, license restrictions (like GPL and sometimes other open source tools often can't be used, especially when building software for resale), and things like that.

Your colleague/friend probably objected to your code not because it uses design patterns per se, but because it's an artificial construct designed to show the use of a specific pattern when another design would have been better (though often subjective, I've (and many with me no doubt) have seen plenty of examples where the forced use of a specific design pattern led to ugly, hard to maintain, and highly inefficient code).

jwenting
  • 9,783
  • 3
  • 28
  • 45