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

TerminologyDsl

Terminology Problem Overview


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:

> domain-specific language (DSL) is a programming language or specification language dedicated to a particular problem domain, a particular problem representation technique, and/or a particular solution technique.

Can anybody give any specific examples of how you have implemented it or how it can be useful in a given scenario?

Terminology Solutions


Solution 1 - Terminology

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.

Solution 2 - Terminology

You can think of DSLs as 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.

Solution 3 - Terminology

(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.

Solution 4 - Terminology

I think it's a language suited to solve problems for a specific domain. It could be some rule-processing language or service description language.

An opposite to a domain specific language (DSL) is a general-purpose language.

Solution 5 - Terminology

Everything is a DSL...

Assembler: MOV R1 to R2
Compilers: Assignment Statements -- A = A + 1, Conditionals -- IF (TRUE) ..., Branch -- RETURN
HTML: ... describe a nested structure
TCP/IP: describe to/from addresses
PDF: describe text/image placement on paper
Fonts: describe characters

Any language that we use to describe a specific process is a DSL. Unfortunately there is a lack of domain specific languages to describe even our most basic processes, so we use the few languages we do have to describe everything we do. "Zip all html files in my web site" requires 300 lines of 3 or 4 different Languages to complete.

To build a DSL determine the minimum number of characters needed to describe a process that you can remember and does not require documentation. Remember that speed and ease of use are the primary design criteria. Parsing is so fast that any syntax you use is fine, I prefer natural language as my syntax in most cases, "Pay Employees at the first of the month", but domain specific is just that, domain specific, you determine the syntax that best fits the problem.

I would stay away from using other solutions that might be convenient but do not fit the problem such as HTML that was used to define Data (XML). CSV is very useful, it fits most problems. JSON does not fit the ease of use portion, it is overkill that adds unnecessary complications were CSV works for most problem. We use EXCEL a lot for DSL, it works great for describing small problems, under 65K to 1M rows, such as a tree structures or menus, column A is the level, other columns are icons, colors, labels and such (EXCEL is an editable CSV).

I found that HTML did not really solve the problem of page layout, so I got rid of it and defined a DSL that does fit. I defined 6 regions on the page, HEADER, BODY, FOOTER, LEFT/RIGHT MARGINS, and LEFT/RIGHT FULL MARGINS. I could then tell the page generator to add a TITLE BAR, STATUS BAR, MENUS, TABLE, FORMS,..., to specific cells. Each of these Cells could then be split into Rows and Columns to any depth. Page layout takes seconds for any style.

BODY contains a Table of my Employees
HEADER contains a Title Bar caption 'Hello World' with login to Collins Software

A Menu DSL don't fit the page layout DSL, so I built a unique DSL for menus.

Resource My Main Menu
*define:menu,m,Level,Label,Icon,Action;
m,0,file;
m,1,open,open.gif,Dialog Open File;

Each problem is unique, the computer can use any format, it is the human that DSLs are designed for, so make it understandable by humans, something they can type in, and make the language out of real words; for it is real people, places, and things that we are describing.

Solution 6 - Terminology

A DSL is a good way to develop a language to be used by non-programmers. For example, if you have a DSL for the finance people in a company, then rather than programming to their specification you can just let them write the program they want done. Then, if it is too slow then you can take what they wrote that works as they want, write it in a compiled language to speed it up.

Solution 7 - Terminology

Well! there is lot of things explained above. I will try to explain this in much simpler way as some one like me come will understand.

As general purpose languages are used for vast purposes the DSL is only made for specific domain. Like HTML or CSS.

You can say if you wrote instructions to a paper which only some person or your only best friend can understand and no one else could. Then it may be a DSL. But if you wrote instruction in such terms which many people could understand and could follow then this is not DSL.

I onces created a Switch board for user which could be operated via Serial port of a computer and User want a program for that board which could be executed on that board and Relay switches will be turned on and off accordingly. So I wrote some instructions and told the user to program that board according to these instructions. This is an example of DSL. I did not invented a new Language rather then I just created bunch of Strings that micro controller could read from EEPROM and could parse accordingly and could perform a specific task.

Solution 8 - Terminology

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.

Solution 9 - Terminology

I've just recently heard DSL but find a really helpful example: LUNA (former lunascript).

It's a custom-made programming language/framework made by Asana team for their own platform.

As I further find, many companies make their own frameworks and languages in order to create a proper competitive advantage, some examples are:

  • SAP with AbAp
  • PeopleSoft with PeopleCode
  • Apple with Objective-C
  • Facebook has things like FBML and FQL

Those are domain specific because you'll use them almost exclusively for working on these platforms.

I hope this answer helps you clarify on the concept.

Solution 10 - Terminology

One simple example for Domain Specific Language(DSL) is HTML which is used for the particular domain called web-based applications.

Solution 11 - Terminology

An example of a DSL used in Machine Learning is patsy in python: https://patsy.readthedocs.io/en/latest/formulas.html#

which is based off the formula DSL from R: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html

https://cran.r-project.org/web/packages/Formula/vignettes/Formula.pdf

and Hadley has a nice section of his advanced R book that describes how to build a DSL w/R: http://adv-r.had.co.nz/dsl.html

Once the deep learning field stabilizes somewhat (or even now) I'd love to see something similar arise inside Apache MXnet project. However, I haven't seen any proposal for that on the proposal page yet though.

Solution 12 - Terminology

Domain-specific languages express your domain processes and knowledge in a language that directly uses the concepts and logic from your particular field.

The community is definitely growing but still not in the level of other "mainstream" technologies.

Most of the time, DSLs are made to improve productivity inside the companies, so they keep it private and don't share their results/insights.

Here is a conference where the speaker gives some examples of DSL using JetBrains MPS, with the technology of Projectional editing: https://vimeo.com/197381453

Solution 13 - Terminology

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.

Solution 14 - Terminology

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSrikar DoddiView Question on Stackoverflow
Solution 1 - TerminologyCharlie MartinView Answer on Stackoverflow
Solution 2 - TerminologyrgzView Answer on Stackoverflow
Solution 3 - TerminologyrndmcnllyView Answer on Stackoverflow
Solution 4 - TerminologyMichael DamatovView Answer on Stackoverflow
Solution 5 - TerminologyClifView Answer on Stackoverflow
Solution 6 - TerminologyJames BlackView Answer on Stackoverflow
Solution 7 - TerminologyAbdul RehmanView Answer on Stackoverflow
Solution 8 - TerminologyAdamJonRView Answer on Stackoverflow
Solution 9 - TerminologyAbraham RomeroView Answer on Stackoverflow
Solution 10 - TerminologyAnil KumarView Answer on Stackoverflow
Solution 11 - TerminologyLucas RobertsView Answer on Stackoverflow
Solution 12 - TerminologyOscar RodriguezView Answer on Stackoverflow
Solution 13 - TerminologyMaciej SikoraView Answer on Stackoverflow
Solution 14 - TerminologyatongsaView Answer on Stackoverflow