3 ms·
I always wonder: these 'patterns', do they simplify programming for beginners? What are they for, really? Why is there a whole set of standard patterns even w
by beeforpork 9y ago
I always wonder: these 'patterns', do they simplify programming for beginners? What are they for, really? Why is there a whole set of standard patterns even with standard names that people find useful? Do they really find them useful?
It seems simplistic to me to cut the world into pieces of 'if you have this problem, you solve it with this pattern, dude.' Isn't this missing the point of really understanding the problem? Especially because (a) the problems are usually not exactly like (so often applying a standard pattern makes the code overengineered) that and (b) the proposed pattern often more reveals the limitations of the underlying programming language, so why is that not mentioned in the motivation of that pattern? Like the 'visitor pattern' -- does any pattern intro tell people that this exists only because Java and C++ have no multiple dispatch? Does is not just awkwardly implement what is naturally expressible in, say, Julia or CommonLisp. Yet I've never seen this as an explanation for that pattern.
For the excessively applied 'factory pattern', it even has it's own jokes: Java, the language without verbs (or, only with 'run()' and 'do()').
Instead of having a simplistic cookbook of patterns, would it not be wiser to teach programmers about problem analysis and programming languages?
TL;DR: I don't understand 'patterns'.
- humanrebar 9y ago> Like the 'visitor pattern' -- does any pattern intro tell people that this exists only because Java and C++ have no multiple dispatch? It's not exactly a secret. The Double Dispatch wikipedia page has a visitor section: https://en.wikipedia.org/wiki/Double_dispatch#Visitor_pattern https://en.wikipedia.org/wiki/Double_dispatch#Visitor_patter... > Java, the language without verbs Right. But in the C++ standard library, they use a version of the factory pattern (see make_shared) to allow for some optimizations and nicer syntax. Separating some construction options from the class definition itself allows for more separation of concerns with no real loss to encapsulation. > I don't understand 'patterns'. I mostly agree that patterns help you work around language limitations. Though having names for concepts is generally helpful to help move the state of the art forward. There are "sidecar", "proxy", and "broker" patterns in system design. If we didn't have those, we'd have to reinvent prose every time we were describing those maneuvers to our coworkers and (even harder) strangers in the industry.
- pcr0 9y agoVisitor pattern isn't just used to overcome language limitations. In Rails it's used to dynamically generate SQL statements for different databases.
- Const-me 9y ago> do they simplify programming for beginners? I don’t think they do. > What are they for, really? To reason about code. To explain to others what the code does. Also to document code. > 'visitor pattern' -- does any pattern intro tell people that this exists only because Java and C++ have no multiple dispatch? Visitors are sometimes useful when you do multiple different filter/search/transform operations on the same tree data structure, especially if the tree contain heterogeneous elements i.e. walking is not trivial. Visitor pattern allows you to write tree-walking code once, and reuse it with different operations = different concrete visitors.