设计模式为(缺少)语言功能 [英] Design pattern as (missing) language feature

查看:62
本文介绍了设计模式为(缺少)语言功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时人们将设计模式称为缺少编程语言功能.为了避免争论什么是设计模式,我们只考虑原始的GoF模式.例如,单例模式在Scala中消失了,它使用关键字object支持单例对象.

Sometimes people refer to design patterns as missing programming language features. To avoid the debate about what is a design pattern, let's say we only consider the original GoF patterns. For instance, the singleton pattern vanishes in Scala which supports singleton objects using the keyword object.

关于这方面的资源很少,尤其是缺少语言功能的设计模式从C2 Wiki或>设计模式真的是语言上的弱点吗?.但是我找不到这个问题的客观观点和全面报道.

There are few resources around about this, notably Are Design Patterns Missing Language Features from the C2 wiki, or Are design patterns really language weaknesses? from SO. But I couldn't find an non-opinionated, objective and comprehensive coverage of this question.

理想情况下,我想要一个带有GoF设计模式(行)和一些主流编程语言(列)的矩阵,其中每个单元格都引用特定编程语言中有关该模式的讨论.

Ideally, I would like a matrix with the GoF design patterns (row) and some mainstream programming languages (columns), where each cell would refer to a discussion about the pattern in the specific programming language.

为了避免有关应考虑使用哪种PL的争论,我们还可以解决此问题并选择:Java(作为静态类型的OO代表),Smalltalk(作为动态类型的代表),Haskell(作为功能性代表),Scala(作为混合oo/功能代表),Lisp(作为元编程代表),JavaScript(作为基于原型的代表).并留出其他PL供注释或评论.我知道我们可以为这种选择争论不休,但是对于这些语言来说已经很有趣了.

To avoid the debate about what PL to consider, we can also fix this and pick: Java (as an statically typed OO representative), Smalltalk (as a dynamically typed representative), Haskell (as a functional representative), Scala (as a hybrid oo/functional representative), Lisp (as a meta-programming representative), JavaScript (as a prototype-based representative). And leave other PL for side notes or comments. I know we can argue about this choice, but that would already but really interesting to have that for these languages.

无论如何,这始终是一个悬而未决的问题,但我想问的是,这已经足够集中,可以提供一个最佳答案.

This will anyway always be an open question, but I feel like asked as it is, this is focused enough to have one best answer.

也许这个矩阵已经存在于某个地方?还是有人有足够的知识来制作它?还是某个人有足够的热情开始并使其成为Wiki答案,以便其他人可以继续?

Maybe this matrix already exists somewhere? Or somebody has enough knowledge to craft it? Or somebody is keen enough to start and make it a wiki answer so that other can continue?

推荐答案

设计模式中的模式是人们在使用不同语言进行编程时使用的不断增长的模式集的子集.作者非常清楚,这些模式仅适用于OOP语言,因此在这种情况下,它们中的许多都没有意义.

The patterns in Design Patterns are a subset of the ever-growing set of patterns people use when programming in different languages. The authors are very clear that those patterns only apply to OOP languages, so many of them won't make sense outside of that context.

同时,OOP语言不需要其他语言中的许多模式.考虑到用C或Scheme实现时,对象本身就是一种模式.在汇编中,调用堆栈是一种模式.

At the same time, there are plenty of patterns in other languages that aren't needed in an OOP language. Consider that objects themselves are a pattern when implemented in C or Scheme. In assembly, a call stack is a pattern.

这篇关于设计模式为(缺少)语言功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆