什么时候应该使用领域特定语言? [英] When should I use a Domain Specific Language?

查看:116
本文介绍了什么时候应该使用领域特定语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于何时应使用域名特定语言,我希望获得一些实用的指导。我已经找到了关于优点和缺点的资源,但是什么样的项目可以保证使用它?

I would like some practical guidance on when I should use a Domain Specific Language. I have found resources about advantages and disadvantages, but what kind of project would warrant its use?

似乎在创建和维护DSL方面投入了大量时间,那么在什么应用程序空间上我可以从时间投资中获得生产力回报?

It seems like there is a big investment in time to create and maintain a DSL, so in what application space would I get a productivity return on my time investment?

编辑:似乎DSL最常见的用途是对于用于保持数据状态的文件格式,使用DSL进行程序逻辑和结构(可能是代码生成)怎么办?什么时候可行?

It seems the most common use of DSL is for file formats for persisting data state, what about using a DSL for program logic and structure(perhaps code generation)? When is this feasible?

编辑#2 我主要是在询问何时创建特定的DSL值得。当然,我们应该尽可能多地使用现有的DSL,以节省时间。

Edit #2 I am mainly asking about when is creating a specific DSL worthwhile. Of course we should use existing DSLs as much as possible to save time.

推荐答案

创建另一个方法的充分理由很少。 DSL。

There are very few good reasons for creating yet another DSL. The world is fat with special-purpose languages.

与这些语言一起思考。


  1. 使用Python,Java,C ++等通用语言解决该问题。

  1. Solve the problem with a general-purpose language such as Python, Java, C++.. whatever.

优化该解决方案以将其排除在外共同的功能,并建立一个非常漂亮,非常优雅,真正可扩展的类库。

Optimize that solution to factor out the common features and build a really nice, really elegant, really extensible class library.

优化该类库以强调正交性。确保所有功能都能很好地协同工作,没有任何问题。

Optimize that class library to emphasize "orthogonality". Make sure all features work well together, without any problems.

如果只需要简化语法,请在漂亮的类库周围创建脚本包装。这是您的DSL。对于Python,这很容易-它已经是一种动态语言。对于Java,您可以利用某些东西。对于C ++,构建这种灵活的脚本环境可能需要一些工作。

If you need simplification of the syntax only, create a scripting wrapper around your nice class library. This is your DSL. For Python, this is easy -- it's already a dynamic language. For Java, there are things you can leverage. For C++ it can be a bit of work to build this flexible scripting environment.

如果仍然需要进一步的优化,请考虑为DSL编写编译器。 / p>

If you still need further optimization, consider writing a compiler for your DSL.

这篇关于什么时候应该使用领域特定语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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