27 ms·
I always tell people who obsess over design patterns as clean code and good coding practices to remember that design patterns often indicate a lack of language
by vrnvu 2y ago
I always tell people who obsess over design patterns as clean code and good coding practices to remember that design patterns often indicate a lack of language features.
For example, are you using a Builder? Would you use the Builder pattern if the language had named variables in arguments?
My favorite reference on the topic is Peter Norvig's "Design Patterns in Dynamic Languages" (1996!) https://www.norvig.com/design-patterns/ https://www.norvig.com/design-patterns/
- davidcuddeback 2y ago> Would you use the Builder pattern if the language had named variables in arguments? Yes, absolutely. I see it all the time in the Ruby ecosystem and have used it myself in Ruby. Many times it gets called by a different name. I've seen it in Python and Elixir too.
- nine_k 2y agoA builder can allow you create different kinds of objects from a common stem. They don't have to be bags of properties. Say, SQLAlchemy is all built on chaining builder-like methods, which make one of the finest DSLs that translates to SQL. In the end, you build a representation of a SQL statement, but in no way could that work with named arguments alone. Instead, consider named arguments as nice shortcuts over curried functions.
- c3534l 2y agoI suppose any feature you need is a design pattern, and everything from functions onup are whys of implementing features your language doesn't natively support.