What is a domain specific language? Anybody using it? And in what way?

前端 未结 14 1687
天涯浪人
天涯浪人 2020-12-22 17:04

I guess I am looking for some kind of intro and see if anybody have used it. Are there any particular advantages of using it?

Wikipedia:

domai

相关标签:
14条回答
  • 2020-12-22 17:41

    nextflow(https://github.com/nextflow-io/nextflow ) is a kind of DSL language written by groovy;

    the main purpose of nextflow is to write pipeline for analysis, and easily trans from laptop to HPC to cloud, and repeat env with conda,docker,singularity

    0 讨论(0)
  • 2020-12-22 17:42

    DSL - domain specific language. Let's start what is domain - domain is some defined area, scope. This domain can be web site look, and you have for it CSS and second domain can be web site structure, and here you have HTML.

    But, domain can be also Company X Application. And in scope of this domain some language can be created. Language does not mean - fully flavored thing with own gramma, syntax, compilator or runtime. DSL can be just a list of tools which solve domain problems.

    Lets consider OOP and its model to represent domain objects by classes and methods as those objects behaviors. If we create such structure, and give these objects behaviors, then we can write a code using those concepts. Consider this pseudo code example:

    cookie = async getCookie(cookieId)
    user = async getUser(userId)
    result async user.buy(cookie)
    if (result.isError()) {
      error.showAlert("User has not enough money")
    } else {
      confirmation.showSuccess("Cookie was bought")
    }
    

    How much from above is GPL (general purpose language) and how much is specific domain terminology and tools. This is a mix of two, but all commands are here domain specific. That said we can say that above is written in DSL where the domain is some application x.

    Going forward with this example I can create even more abstract tools, and mostly perform the control flow by those tools, consider (this is more FP, but hope you get what I mean):

    waitForMany(getCookie(cookieId), getUser(userId)
      .andThen([cookie, user] -> user.buy(cookie))
      .andThen(showSuccess("Cookie was bought"))
      .whenError(showError("User has not enough money"))
    

    As you can see I was able to abstract quite a lot and use this abstraction to perform the control flow. And everything is based on GPL and works in scope of GPL.

    To reveal the truth, we all write DSL, every domain specific abstraction which u can use is kind that. But most of those abstraction are not complete solutions, that is why we tent not to use this word too often. But if you have set of tools, functions which abstract your domain, they form kinda DSL.

    What is also DSL, many things, for example any framework which provides set of rules is DSL. If you see somebody is claiming he is React developer, then you know he is Domain Specific Developer, as React is exactly DSL which is alternative for using native web platform. If you can compose functionality from existing domain specific tools then you are writing using DSL. Going deeper in React, sorry all folks not from this DSL :D, you can create set of components, and compose them as building blocks, and hurra!, now you made DSL on top of DSL.

    Yep repeated DSL too many times here, sorry.

    0 讨论(0)
  • 2020-12-22 17:43

    You can think of DSLs as overly complex arguments for functions written in a more general programming language. The real programming language parses the DSL code and does something with it, typically, the DSL code only focuses on the what you want to do, and the larger system figures out the how.

    Examples of DSL include all query languages (SQL, XPath, ...), all template languages (Django, Smarty, ...), shell scripts, especially including stuff like twill, a command driven web browser (mostly used for automated test), data storage and exchange languages (XML, YAML, ...), and document languages like LaTex, HTML or CSS.

    Some languages with very flexible syntax like TCL and Lisp build their DSL directly into the language... when possible. The majority of languages use strings, usually loaded from external files.

    Are there any particular advantages of using them? Using them for their intended purposes is very advantageous to the point you will turn to them without knowing, just like you have been using (I presume) SQL or HTML without thinking of them as DSLs.

    I'll dare saying there are enough DSLs out there for any sort of application you may need; you almost certainly don't need to learn how to write your own one.

    0 讨论(0)
  • I've written a brief blog post discussing why I like using DSLs:

    I Wish We Used Domain Specific Languages (DSLs) More

    In it, I define a DSL as:

    A small programming language specifically designed to communicate solutions for a particular domain of problems.

    In terms of use, if you've ever used Ant, Structured Query Language (SQL), or Cascading Style Sheets (CSS), you've used a DSL.

    I like using DSLs because they focus on facilitating the communication of solutions to specific problem spaces, and they do so in a way that promotes the inclusion of domain experts.

    0 讨论(0)
  • 2020-12-22 17:46

    A domain specific language is a language that's written to deal with a specific domain or set of concerns. There are a lot of them around, like make, ant, and rake for describing software builds, or lexx and yacc for language construction. In recent years, they've become popular as some things have combined to make them easier to build. Big among those things has been the increasing popularity of Ruby, which has several features that make it easy to build new DSLs.

    Martin Fowler is a big proponent of the idea, as here.

    0 讨论(0)
  • 2020-12-22 17:46

    (addressing the crux of the question)

    I think the first time I saw DSL somewhere and its definition as "domain specific language" I also thought it was a particular, concrete language that I just hadn't heard about -- but, no, its a general term for languages that are tailored to a particular application area.

    Ironically, if you had just heard about TCL as a "tool command language" you might think, like DSLs, that there would be lots of TCLs for various tools -- but, no, its the specific name of a particular scripting language.

    0 讨论(0)
提交回复
热议问题