是项目特定的DSL负债? [英] Are Project-Specific DSLs a Liability?

查看:176
本文介绍了是项目特定的DSL负债?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从分叉我评论我的许多伟大的答案我收到一个提出了一个类似的问题,这一问题。原本我是问AST宏,它主要引起了Lispers非常细致,周到的答复。谢谢你。

I've forked this question from a similar question I made in a comment I made to one of the many great answers I recieved. I was originally asking about AST macros, which mostly provoked very detailed and thoughtful responses from Lispers. Thanks.

懒惰的评价VS宏

我评论提出的问题是特定项目的DSL是否真的是一个好主意。当然,这完全是主观的 - 毕竟,当你正在写在一个真正的前pressive语言,你在哪里绘制前pressive API和实际DSL之间的界线?例如,我想大多数Ruby开发者称之为'DSL的'实际上只是精心设计的API,仅此而已。

The question I made in a comment was whether project-specific DSLs are actually a good idea. Of course, this is completely subjective -- After all, when you are writing in a really expressive language, where do you draw the line between an expressive API and an actual DSL? For example, I think what most Rubyists call 'DSLs' are actually just well-designed APIs and nothing more.

请注意,我说的具体项目的 的API。我不认为很多人会反对使用常规的前pressions或SQL的地方是有道理这样做。

Note that I say project-specific APIs. I don't think many will argue against using regular expressions or SQL where it makes sense to do so.

但是,尽管这样,我觉得我们都可以得出一个API和DSL之间的vauge,朦胧行。当然,他们都是真正的API,但不管。

But despite this, I think we can all draw a vauge, hazy line between an API and a DSL. Of course they're both really APIs, but whatever.

在一个极端你有Lisp语言,其中的DSL似乎通过宏来积极鼓励。另外你在那里的DSL是pretty很多不可能的。

On one extreme you have Lisp, where DSLs seem to be actively encouraged via macros. On the other you have the likes of Java where DSLs are pretty much impossible.

DSL的支持者会争辩说,他们提高灵活性,前pressiveness,增加稠度(例如,使用相同的运营商为语言本身的数字自定义数字对象)。

Proponents of DSLs would argue that they increase flexibility, expressiveness, and increase consistency (for example, a custom number object using the same operators as the language's own numbers).

批评者会说,他们可能会导致没有人除DSL作家知道子语言,杀死在首位具有不同的编程语言的角度来看,并导致code没有人能理解,因为的方式< STRONG>接口与API是不同的。

Detractors would say that they can lead to sub-languages that nobody except the DSL writer knows, kills the point of having different programming languages in the first place, and leads to code nobody can understand because the way of interfacing with API is different.

我得说,我在很多方面双方达成一致。一些Java API是只是一般肮脏的,由于缺乏前pressiveness的。尽管这样,我一般总是工作发生了什么事情在没有阅读文档 - 可以不是丝毫定制的DSL说。也许DSL支持者认为你应该的总是阅读API文档。我不同意,但我也离题了。

I gotta say, I agree with both sides in many ways. Some Java APIs are just plain nasty due to the lack of expressiveness. Despite this, I can generally always work out what's going on without reading the documentation -- Which can't be said about custom DSLs in the slightest. Maybe DSL proponents argue that you should always read API documentation. I disagree, but I also digress.

但是,让我们看看一些在目前的大语言。 C#和Java,即得。他们既不真正做的DSL,但他们是大规模流行。这是precisely因为他们的允许之类的DSL,让平庸codeRS生产出code这仍然COM prehensible?

But let's look at some of the big languages at the moment. C# and Java, namely. Neither of them really 'do' DSLs, yet they're massively popular. Is this precisely because they don't allow things like DSLs, allowing mediocre coders to churn out code that's still comprehensible?

的事实是,DSL的允许平庸codeRS产生坚不可摧的垃圾为什么Lisp是不使用尽可能多的,因为它应该是,原因是什么,尽管是DSL能像在右手?

Is the fact that DSLs allow mediocre coders to produce impenetrable garbage the reason why Lisp is not used as much as it should be, despite what a DSL can look like in the right hands?

推荐答案

有当然论​​点支持DSL的,反对他们,当然还有一库或API和之间的模糊线DSL。这部分你在问题中所涵盖很好,所以我会避开那些主观点和着力无论他们是刚刚责任的问题。

There are of course arguments in favor of DSLs and against them, and there's of course a vague line between "a library" or "an API" and "a DSL". That part you've covered well in the question, so I'll avoid those subjective points and focus on just the question of whether they're a liability.

一个好的项目来考虑,这是球拍这使语言建设为主要特征。这很容易就打了语言的语言的定义是:通过通过定义新的语言和可能的解析器宏做了一个跨preTER或(更常见)DSL与否,从近从头组成不同的语法。其结果是,球拍源代码树有语言一群 - 他们中的一些具有根本不同的执行语义。一些例子:

A good project to consider for this is Racket which puts language construction as its main feature. It's easy to slap up a language for any definition of "a language": DSL or not, made up from near scratch via an interpreter or (more commonly) done via macros that define the new language and possibly a parser for a different syntax. As a result, the Racket source tree has a bunch of languages -- some of them have fundamentally different execution semantics. Some examples:


  • 懒球拍是你所期望的名字的意思,

  • Lazy Racket is what you'd expect the name to mean,

类型化的球拍是静态类型语言,

涂鸦是用于编写文档和其他散文的语言,

Scribble is a language for writing documentation and other prose,

幻灯片是写作......幻灯片的语言,

Slideshow is a language for writing ... slideshows,

RackLog /的 DATALOG 是,即使是在这两个语义<更多种不同的语言EM>和的语法。

RackLog/DataLog are languages that are even more different in both semantics and syntax.

事实上,弥补语言是球拍那么容易,你很容易就打起来,即使它的东西,一个适合使用非常有限,甚至只是一个单一的语言。例如,我们有一个用于创建我们的网页,决定在分布式安装哪些文件包含这样的小语种,和许多许多。请参见本教程获取如何拿出一个语言的描述。

In fact, making up languages is so easy in Racket, that you easily slap up a language even if it's something that fits a very limited use, or even just a single one. For example, we have such "small languages" that are used to create our web pages, decide which files are included in distributed installers, and many many more. See this tutorial for a description of how to come up with a language.

这是真的,有一个有用的DSL,很多人可以使用,而且只有一个人使用一个在一线之间 - 但仍然,那种抽象的,在定义的语言而不是的是巨大的,到这是一个有用的概念,即使它是一个人的语言的地步。这是一体的难题正在考虑互操作性 - 球拍可以在它自己的语言,它带来了的当数这些模块都应该互相沟通发生了什么问题被写入每个模块。例如,如何做评估收益时,有在慵懒的语言和默认的功能互动;或如何类型化确保它可以用默认的类型化的语言交流,仍然可以得到一个静态类型语言的常用好处。

It's true that there's a fine line between a useful DSL that many people can use and one that only one person uses -- but still, the kind of abstractions that you can get when you define a language rather than a library are substantial, to the point that it's a useful concept even when it's a "one-man's language". One hard problem in this are is considering interoperability -- Racket allows each module to be written in it's own language, which brings up issues of what happens when several of these modules are supposed to talk to each other. For example, how does evaluation proceeds when there's interaction of functions in the lazy language and in the default one; or how does the typed make sure that it can interact with the default untyped language and still get the usual benefits of a statically typed language.

这篇关于是项目特定的DSL负债?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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