9 ms·
It 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
by userbinator 11y ago
It 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.
- eru 11y agoOr rather, they can become either invisible or first class citizens that you can assign to a variable and pass around.
- TeMPOraL 11y agoNo, they disappear completely. You stop thinking in terms of "factories" or "strategies" and start to think in terms of simply passing methods around, etc.
- ajuc 11y agoI still think "oh, a generator function" when I program in clojure. I'm just not excited every time I got to use it. That's all the difference IMHO. Also - there are such "nonexciting patterns" in OOP languages as well, and they are much less often abused. For example "a switch inside a while" pattern. Which I think I will need to name "StateMachinePattern" to make it cool and stop people refactoring it into strategies and stuff. There is value in one-screen definition of the whole machine, instead of separating it into 6 files.
- maffydub 11y agoAgreed. I never really saw design patterns as a reference manual for how to solve problems (as I think some people do/did). Instead, I saw it as a shared vocabulary. For example, if I say that X is a factory for Y or an iterator over Z, you know exactly what I mean.
- eru 11y agoWe still have monads and functors in Haskell. People in other languages have eg picked up the `monad' pattern. (Look for eg `flatMap' to spot it; that's monadic bind.) In Haskell even the compiler knows that there are common elements to all instances of the monad pattern---they can reference a common typeclass. (But even if you don't implement an instance of the typeclass, you might still have implemented the monad pattern, but just don't realize it.) In eg JavaScript it's all by convention only. But even in Haskell, the compiler does not enforce all monad laws, yet. A more common example, but perhaps invisible today, is the `function' pattern. In most assembly languages, functions are a convention only, and you have to manipulate your call stack somewhat manually. In almost all languages anyone is using these days, that's done automatically. Functions are not `invisible' but they are citizens with more right, ie the compiler / interpreter knows about them, you can give them a name, and in some more modern languages even pass them around, or _not_ give them a name. Some patterns do become invisible as you say. `Factories' are one that only exists because of weird restrictions in eg Java. They are invisible in Python. In Haskell for different reasons we have a similar solution where we define extra functions to return our create our objects instead of using constructors directly. Instead of factories, people call these smart constructors (https://wiki.haskell.org/Smart_constructors https://wiki.haskell.org/Smart_constructors). Smart constructors in Haskell could go away with a stronger type system like in Agda. (Yes, there are languages with stronger types than what Haskell has.)
- eru 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 did some OO, but like functional programming better. In Haskell, there's a certain draw to doing everything in the type systems. Or a quest to find the single abstraction that unifies all your code into a coherent whole. (For a configuration language pretty printer that I worked on at Google, I recently managed to throw out a couple hundred lines of code, by finding a unifying abstraction for most of the recursive functions on the abstract syntax tree we were doing.)
- acdha 11y agoI sometimes describe it as “framework envy”. I've worked with a fair number of developers who learned library design by looking at the standard library or popular frameworks and thought it was a model for everything, unaware that in many cases those were either poor examples (e.g. AWT / Swing) or complicated by offering a general solution usable for a wide range of projects and thus overkill for an internal app which would never be used elsewhere, especially when the core structure was still being determined.
- TeMPOraL 11y agoIt's something to grow out of. I had that "framework envy" towards game engines in my early years, and was designing overcomplicated architectures for a while.
- sbov 11y agoI think this hits the nail on the head. I would say that more generally, a not insignificant number of OO design concepts were developed in an environment of coding modules meant to be used by other people (either in the form of frameworks, or multi million line monoliths). For a large number of developers, neither of these environments apply, but they are still abiding by the same rules.
- acdha 11y agoYeah, it's like reading about some cool thing Google or Facebook is doing and then recognizing that your problem is much easier because the data fits in RAM
- mizchief2 11y agoI think the Gof and other patters are good to study and understand at an academic level, but you shouldn't go looking for how to apply a flywheel to your application. Just design the system the way you think it should work and you will instinctively apply the patters as they fit.
- richmarr 11y agoDoes anyone know how the Design Patterns authors became known as the "Gang of Four"? I'm guessing it originated from an unflattering comparison, although my knowledge of the Cultural Revolution is pretty weak, maybe it was a compliment.
- vram22 11y agoNot sure, but 4 co-authors is a likely partial reason. Also I guess partly due to imitating various precedents, and not just in tech. E.g. The Three (Musketeers, ...), The (..., ...) Duo, The Famous Five (kids novel series), etc. A separate HN thread on that might be a fun read :) A similar one is eponymous Laws (Wikipedia has a list).
- philk10 11y agoSee here - http://c2.com/cgi/wiki?GangOfFour http://c2.com/cgi/wiki?GangOfFour
- richmarr 11y agoYeah, I don't feel any enlightenment kicking in. I'm aware that the Gang of Four name originated with a cabal of power at the centre of Maoist China, but I'm curious who drew the connection and why.
- vram22 11y agoWell, going by further events related to the use of design patterns (as discussed in the article and, e.g. userbinator's comment (which was at the top of this thread), maybe the connection is "comply, or you will be assimilated" ...
- pc86 11y ago> so they think "awesome, something new and shiny to use in my code!" and start putting them in whenever they can Yeah. You do not truly know hell until you're trying to maintain a basic CRUD app used as a tool for someone to learn domain-driven design, CQRS, and event sourcing simultaneously.
- Benjammer 11y agoI'm always curious about whether or not people are lumping in lower-level "coding best-practice" concepts like DRY in with this idea of "complexity." It's fine to complain about people who "over-engineer" things, but I've also come across cases where someone uses "I'm Agile" as an excuse to completely throw out any and all coding structure or best practices. And every time I try to say that maybe we should spend 3 seconds to remove the comments that are in Chinese and maybe adapt the code to our naming conventions after literally copy&pasting it in from StackOverflow, I get pointed to arguments like this post for why none of that stuff matters.
- deong 11y agoNo one is against coding structure, or even "best practices", if you interpret it as meaning the thing someone fluent in English but with no background in software development would understand it to mean. The problem is that "best practices" in our industry has become a specific term meaning "overly complicated by a factor of about seven, but with enough meaningless jargon invented to describe it that no one feels comfortable saying the emperor is in fact naked".
- Benjammer 11y agoI totally agree with you, I just think that the ideas being discussed in this thread have a ton of nuance and they can be dangerous to introduce to a junior developer who doesn't quite realize the difference between the idea of "complexity" we're talking about here and the fact that he shouldn't be copy-pasting boilerplate code all over the app and copy-pasting directly from StackOverflow without any editing or integration of the code.
- lgunsch 11y agoI would agree with that definition has become the new interpretation of "best practices". However, in my 5 year career I have seen the majority of solutions under-engineered. That is much more of an issue these days than over-engineering.
- Benjammer 11y ago
- dahart 11y ago> the majority of developers, who for some reason appear to love immense complexity and solving simple problems with complex solutions. It took me a while to break out of what I learned in school about how to write software. My single most important takeaway has been to not seek generalization and abstraction of the problem I'm working on, but solve it as directly as possible, and only generalize or abstract my code after I've completely finished solving the same problem at least twice. In my experience, the single biggest software time waster I've witnessed (and participated in) is people solving problems they don't have.
- treehau5 11y agoIn school are students not always taught to solve using the naivest implementation possible, and then improve?
- dahart 11y agoMy classmates and I were taught to use the most naive code possible, and then improve it immediately using patterns that abstract and generalize the problem being solved. We were taught to look for improvements that solve problems of safety and scale, we were taught to look for ways to use existing design patterns. Those are important basic software skills to learn, but in my schooling they were never offset by a philosophy that dealt with how and when to use them, and more importantly, when not to use them. I've personally seen in my ~20 year professional software career so far a lot of software engineering that is overly expensive by a long way because people decide to add unwarranted complexity.
- noxToken 11y agoThe first time I was told, "Make it work, make it right, make it fast," was in my first programming course. However, it was in passing by another professor substituting. After the first programming course, we had OOP Design. It's how to better structure OOP software, abstractions and design patterns. This was our, "This is how good programmers do it." That same professor who had subbed then beat it into our heads - in our senior level programming languages course - that making the damn thing work takes priority over all. I guess better late than never.
- huherto 11y agoOften is about developers trying to make their systems flexible. In software. You can make any part of a system flexible. You can make several parts of a system flexible. But the more flexibility you add the less maintainable the code becomes, and there for the least flexible overall. So you really have to choose where do you want that flexibility. Often is better to keep your design simple and clean; and add the flexibility when you actually need it.
- AnimalMuppet 11y agoYes. The most general problem cannot be solved. So only generalize where you need to.
- mavelikara 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. Unrelated to your original point, you should consider reading the book. Pay special attention to the section introducing the motivation for each pattern and the problem it solves. Over-engineering programs to deliberately include patterns is to be avoided; but there is no harm is knowing the patterns and when they apply by reading the original material.
- gerbilly 11y agoOk but under-engineering can also be a problem. Say you and your team are going to build a REST server that will serve hundreds of endpoints. Nothing complicated, just a bunch of CRUD code with some business logic. So here is the simple way to write each endpoint function, or method. RESTResponse getUserPrefs(Userid id) { return DB.getUser(id).prefs; } except you need security and code to setup and teardown DB the transaction. RESTResponse getUserPrefs(Userid id) { if( !Security.checkAllowed(id) ) return REST.403; RESTResult result; DB.getConnection(); DB.beginTransaction(true /*Readonly*/); RESTResult result = DB.getUser(id).prefs; DB.endTransaction(); DB.closeConnection(); return result; } Now imagine giving this example to a team of devs to develop those hundreds of bitty REST endpoints. Also as you can imagine, the boilerplate introduced here may have to change per endpoint. There might also be other boilerplate that may need to be added for object level security, authentication, error logging etc ... So when you throw this code at your developers, it means that you'll end up with hundreds or thousands of little methods all similar but all different. They are going to cut and paste this example and modify as they go. They may come up with better ways to structure the boilerplate, leading to some old code mixed in with code written in a newer style. Good luck working with that after a few years. All these encomia for simple code usually considers only a single small program, with one person working on it. Once code is loosed in the wild for a team of maintenance programmers to work on, you have a whole new problem, and lack of structure form the simple approach will cause weeds and vines to choke your codebase.
- acveilleux 11y agoGenerally, it's much easier to add complexity than remove it once it has been added. > So when you throw this code at your developers, it means that you'll end up with hundreds or thousands of little methods all similar but all different. If that's what happens with your developers, you need new developers or new management, clearly the ones you've hired are either incompetent or their management is forcing them to suck.
- gerbilly 11y ago> If that's what happens with your developers, you need new developers or new management I don't think so, it's just human nature and other pressures besides the purely technical ones: like the pressure to just get a task done, or to get the job done as easily as possible, and so on...[1] As programmers we tend to think the the biggest challenges are technical, but they aren't: the social problems are a way bigger factor. Also the problem I'm describing here applies to large low-complexity codebases, to be worked on by large teams. These are common in 'enterprise' settings, which is why I think design patterns have so much appeal there. [1] https://en.wikipedia.org/wiki/Tragedy_of_the_commons https://en.wikipedia.org/wiki/Tragedy_of_the_commons
- misja111 11y ago> the majority of developers, who for some reason appear to love immense complexity and solving simple problems with complex solutions. This is so true. Of all the projects which I have seen that failed, not a single one failed because its design was too simple. In fact, almost all of them failed because they were over engineered and because of that it was too hard to quickly adjust to changing requirements. And still people keep making the same mistake over and over again. It's not just related to design patterns, it's everywhere in the IT world. Take for instance protocols. SMTP: before the 80's there was a whole bunch of mail transfer protocols, many of them quite sophisticated. But which one won? The Simple mail transfer protocol. Or HTML, which was derived from SGML, a more complicated and much more generic protocol. The simple protocol won again. Or XML (derived from the more generic SGML), which is now being replaced by the even more simple JSON. The list goes on.
- Pica_soO 11y agoYou must use the fancy words- its not just a pointer to common constant struct- its the flyweight pattern. If you just use the pointers and not the words you are not a professional.