3 ms·
Any Design Pattern identifies a failing in the core language or its standard library. Were the language up to the job, the pattern would have been captured in
by ncmncm 6y ago
Any Design Pattern identifies a failing in the core language or its standard library.
Were the language up to the job, the pattern would have been captured in a named library component, and no longer be a Pattern at all. Use of a well-designed and -tested library component is always better than re-coding the pattern again at each new use.
A classical example is the hash table. In C, and similarly limited languages, you cannot write a useful hash table library. Instead, custom hash tables are re-coded over and over again in thousands of individual programs and libraries wherever they are needed.
In other, similarly limited languages, the pattern is pulled into the core language, as a "dictionary" or "map" type, eliminating most need to re-code it, at the expense of flexibility in its design.
In more expressive languages like C++ and Rust, hash table libraries arise, and the most commonly useful forms appear in the standard library.
We have continually added to C++ and its library as we have identified patterns. New patterns arise in composing existing features and library components, so adding to them creates new opportunties for patterns to arise. As each new pattern is identified, it may be captured. Sometimes this demands new core language support for abstraction, as is seen in new Concepts and Coroutines core features. So, we naturally expect to see new library components that use the new features in commonly seen ways.
The expected addition of pattern matching to core C++, similarly to what appears in Rust and certain other languages, represents a lapse: a failure to discover and specify core language features to add that would enable implementing usefully general pattern matching as a family of library components. Conflict over, e.g. simplicity vs generality, in design of the core feature is unavoidable, where, were it implementable as a library, different choices could be captured as different library components.
Anytime we lapse and fail to discover core language primitives needed to implement a high-level construct, we should remember and see each use of it as a rebuke, and motivation to invent core features that would have made it redundant.
- throw_m239339 6y agoDesign patterns aren't data structure though, I agree with the rest of your statement. OO Design patterns are usually about implementing functional concepts into rigid OOP languages such as C++ or Java (though both languages have gotten better). With first class functions, there is no need for factories or strategies, or commands or a lot of stuff that imply single method classes. With pattern matching, there is no need for chains or responsibility and so on and so forth...
- ncmncm 6y agoA design pattern is anything you see hand-coded in multiple programs. We don't often see data-structure patterns nowadays just because such patterns were recognized early as in need of core language features to capture them into libraries. Hash tables were a tough nut, so the core features that are needed to capture them in libraries, or even direct core-language implementations, didn't make it into some of the languages that are still in common use. The set of patterns that can be captured into a library is a moving target for a language that is still evolving rapidly, and for the landscape of new and upcoming languages; but a fixed target for a mature language like C. In C, X can, Y can't, and that will probably always be true of C. As time goes on, the set of patterns that can be captured into libraries of new and evolving languages grows, and with it our expectations of new languages. A language, new or old, that fails to capture what other languages are seen to do (for reasons) is rightly seen as less powerful. There is a place for less powerful languages, for use in limited domains, that are therefore quicker to learn and maybe safer to use, for less experienced or more distracted users. But we should always be clear about why the language is being made or kept less powerful, and what is lost by it. When starting a new project with open-ended goals, we don't know what challenges the project will face and whether a deliberately limited language will be enough for the job. By the time we learn, it is generally far too late to change horses. Thus, aging OS kernels and databases we use are often still coded in C largely because that was all that was practically available when they started out. Go is a recent deliberately-limited language that, because it was chosen to implement projects with open-ended goals, is getting painful extensions, and getting harder to learn. Rust was deliberately limited to reduce the burden of implementing its toolchain and to make it easier to pick up, but is rapidly expanding (according to plan) to satisfy the growing needs of its increasingly sophisticated user base.
- throw_m239339 6y ago> A design pattern is anything you see hand-coded in multiple programs. It's like claiming an algorithm is a design pattern. No. In the context of GoF as talked in the linked article, a design pattern isn't anything you see hand-coded in multiple programs.