DSL 与普通旧库

发布于 2024-08-07 19:11:53 字数 360 浏览 3 评论 0原文

我最近一直在思考 DSL 与库的问题。在我的领域,DSL(我想到的是 R、SAS 和 Matlab)的问题在于,它们是编写更通用代码的 PITA,也是集成到其他语言中更通用代码的 PITA。我并不是说这两者都不可能,只是令人烦恼和沮丧。

这与 NumPy 等方法形成鲜明对比,NumPy 运行在通用语言之上,如果它存在的时间和投入的资金一样多,它可能会和 Matlab 一样好。这使您可以处理一个只有一点点数字的项目,而不需要一大堆糟糕的粘合代码来在语言之间进行交互,也不必记住多种语​​法等。

与普通的旧库相比,独立 DSL 的优点是什么用通用语言?似乎在与更通用的代码集成更困难以及需要学习另一种语法方面存在如此明显的缺点,我只是无法理解为什么这些 DSL 如此受欢迎。

I've been thinking lately about the question of DSLs vs. libraries. In my field, the problem with DSLs (R, SAS and Matlab come to mind) is that they're a PITA to write more general purpose code in and a PITA to integrate into more general-purpose code in other languages. I'm not saying either is impossible, just annoying and frustrating.

This contrasts with the approach of, for example, NumPy, which runs on top of a general-purpose language and would probably be as good as Matlab if it had existed for as long and had as much money poured into it. This allows you to work on a project where only a little bit is numerics without needing a whole bunch of crufty glue code to interface between languages, having to remember multiple syntaxes, etc.

What are the advantages of a standalone DSL over a plain old library in a general purpose language? It seems like there are such obvious disadvantages in terms of more difficult integration with more general-purpose code and yet another syntax to learn that I just can't understand why these DSLs are so popular.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年华零落成诗 2024-08-14 19:11:53

独立 DSL 的主要优点之一是它可以更具表现力。在用通用语言编写的库中,您受到该语言语法的限制。考虑一个银行软件的示例,该软件具有一些可以查询的财务记录,并且您希望找到去年的所有抵押贷款问题。使用通用语言进行查询的伪代码看起来像这样:

List<Mortgage> mortgagesThisYear = new LinkedList<Mortgage>();
for ( Mortgage m : mortgages )  {
  if ( today.minus(m.getDate()) <= 1 year ) {
    mortgagesThisYear.add(m);
  }
}

现在在 DSL 中,您可能可以编写如下内容:

Find all mortgages in the last year

更重要的是,银行家可以基于“通用语言”构建这些查询。 (一种通用的领域语言,使程序员和银行家更容易沟通)。

独立 DSL 的目的是非常具体的,而不是通用的。语言更具表现力,语法通常更宽松,与领域更相关。

One of the main advantages of a standalone DSL is that it can be more expressive. In a library written in the general purpose language, you are limited by the syntax of the language. Consider an example of banking software that has some financial records that can be queried and you want to find all mortgages issues in the last year. Pseudocode for a query in a general purpose language would look something like:

List<Mortgage> mortgagesThisYear = new LinkedList<Mortgage>();
for ( Mortgage m : mortgages )  {
  if ( today.minus(m.getDate()) <= 1 year ) {
    mortgagesThisYear.add(m);
  }
}

Now in a DSL, you might be able to write something like:

Find all mortgages in the last year

More so, bankers could construct these queries based on a "ubiquitous language." (a language of the domain that is common and that makes it easier for programmers and bankers to communicate).

Stand along DSLs are meant to very specific and not general purpose. The language is more expressive and the syntax is generally more relaxed and more related to the domain.

死开点丶别碍眼 2024-08-14 19:11:53

外部 DSL 的缺点不适用于使用代码生成和代间隙模式实现的外部 DSL。然后通过所使用的一种通用语言进行接口。
实际上,内部DSL还有很多缺点,比如没有良好的可读显式结构、糟糕的编码实践、有限的具体语法可能性、没有工具支持、很难或不可能实现领域特定的验证以及与其他代码的接口问题。太隐晦了。

The disadvantage of external DSLs doesn't apply for external DSLs implemented using code generation and generation gap pattern. Interfacing is then made through the one general purpose language used.
Actually, internal DSLs have many more disadvantages, like no good readable explicit structure, bad practice coding, limited concrete syntax possibilities, no tools support, very hard or impossible to implement domain specific validations and interfacing problem with other code, when the DSL implementation is too criptic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文