3 ms·
Generally speaking, most design patterns reveal weaknesses in the languages where they are found. Regularities that can be captured in libraries do not become d
by ncmncm 6y ago
Generally speaking, most design patterns reveal weaknesses in the languages where they are found. Regularities that can be captured in libraries do not become design patterns because they end up expressed in one or a family of libraries, and just used. Others, heavily used, are often pulled into the core language.
So, in a stronger language, fewer of the design patterns noticed in other languages are seen. The strongest languages show least use of common design patterns, and also the fewest of them pulled into the core language, because their ability to capture patterns in libraries is better.
An example is the lowly hash table.
In C, this is a design pattern, and there may be millions of more or less independent implementations of the pattern in the corpus of C programs and C libraries. A hash table library in C just cannot be made very widely useful.
Many, many other languages provide hash tables, often called dictionaries, in the core language. It doesn't matter so much, then, that you can't usefully code one in the language, because the language fills that gap. It does mean that if you need a substantial variation on the basic hash table pattern, you are out of luck, but almost all small programs, and even most big ones, don't need anything fancier.
A few languages, notably C++, the MLs, Haskell, D, and Rust among them, are strong enough to capture the pattern in libraries, and you find libraries in these languages implementing numerous variations on the hash table pattern.
There are still patterns that cannot be captured in libraries even in these languages. That failure can help to guide development of useful new features in these languages. The most useful new features enable the language to capture more usage patterns in libraries, so they be coded just once (or a few times) and then used anywhere.
Being able to capture a pattern in a library is much better than pulling it into the language core, because then you get not just the basic pattern, but as many variations on it as turn out to be worth coding a library for.
- jecel 6y agoIt seems odd to talk about hash tables as design patterns. To me they are just a data type. It is true that other languages have a built-in implementations and yet others have a standard user level implementation while in C there are many. But I see design patterns as a framework level thing. What you wrote about them being different in different languages is true, however. When the book came out we had a thread in the mailing list for the Self programming language looking at the 23 patterns and nearly all of them took no special effort to use in Self. An object could be a Singleton, for example, by simply not having "traits clonable" as a parent like most objects did.
- ralphc 6y ago"Generally speaking, most design patterns reveal weaknesses in the languages where they are found" Here's a slide deck from Peter Norvig on this, Design Patterns in Dynamic Programming. He shows how many of the 23 design patterns aren't needed in languages such as Lisp or Dylan, both of which have multiple dispatch. No doubt you could apply the same philosophy to Julia today. https://norvig.com/design-patterns/design-patterns.pdf https://norvig.com/design-patterns/design-patterns.pdf
- musicale 6y agoI'd like to see Dylan-style multiple iterator syntax in more languages. Python's zip() isn't nearly as obvious, and I wish we could do something like this in java/c++: for (a:A, b:B, c:C) ...