(no title)
jchnxu
|
2 years ago
Agree. And I feel like some patterns emerged from the limitations of programming laguauages Java & C++ which does not apply to languages like python/js. I mean when you can use lambdas/high order functions a lot of those patterns does not even make senses. Not to mention those pure functional programming languages.
dingosity|2 years ago
I do, however, agree that "programming to pattern" can be a cringe experience if you're trying to force code into a pattern it isn't intended to hold. And you're right that the original Gang of Four book really was focused on C++ like languages.
Lisp and O-Caml DEFINITELY have patterns. Python ABSOLUTELY has patterns. JavaScript CERTAINLY has patterns. But yes, they're not exactly the same as patterns you find in C++, Java or C#.
Patterns are also useful to communicate concepts to peers. Saying something as simple as "I used an abstract factory pattern on this interface" is much simpler than explaining in detail how your constructor worked. I mean, you might want to write down some details about the constructor, but referencing a standard pattern is a quick shorthand.
I think the concept of patterns is extremely useful. The Gang of Four Design Patterns book is less useful if you're using Python than if you're using Java. But that doesn't mean its useless. And if your code doesn't fit inside a well-defined pattern, that's completely okay. There are more developers who have gone to the trouble to remember a few of the more popular design patterns than in the old days, so it might be easier to communicate your intent if you use a "standard" pattern. But again... design patterns are supposed to help you out, not tie you down. And if you're coding in Python or JavaScript, consider searching for "Design Patterns in Python" or "Design Patterns in JavaScript."
(and as an aside... when they added the "class" keyword to JavaScript, a small part of me died inside. JavaScript was designed with prototypal inheritance (like Self), not class-based inheritance (like Smalltalk.) Insisting that a "class" keyword be added to the language was like arguing for reducing the expressiveness of the language. But I digress. I mention it only to point out "I feel your pain" in issues of other people needing to impose their mental model on an unsuspecting development environment.)
But I believe patterns are useful not so much to help you code, but to help you communicate your intent to others.
kazinator|2 years ago
E.g. Visitor Pattern.
Lisp programmer be like: I'm a gonna recursively walk this tree of objects, and call a generic function with each object from the tree as one argument, and one specific object as the other argument. Done!
C++/Java programmer be like: I'm gonna study the Visitor Pattern again, and then prepare a bunch of skeleton code ...
jchnxu|2 years ago
patterns as a concept for communication are helpful.
But I mean for people coding in in python & js creating singletons are overkill right?