HACKER Q&A
📣 hans1729

How to get started with DSLs and meta-programming?


Hello,

for quite a some time, I wanted to get started with these areas. Now I have some time on my hands, but I don't really know where to look, or frankly, what exactly to look for.

My goal is to "teach my machine to program for me" (I hope you get the gist in the context of this posts title).

What do I want to look for? What prerequisites should I consider? ...

Thanks in advance,

Max


  👤 CyberFonic Accepted Answer ✓
There is a massive amount of material out there. The keywords that you might want to search on are: MBSE: Model Based Software Engineering; MDD: Model Driven Development; MDE: Model Driven Engineering; generative programming. UML is also one of the core technologies.

Some tools to look at: MPS by JetBrains, MetaCase.

The website: https://modeling-languages.com is rather useful. The article: https://scihub.bban.top/https://doi.org/10.1007/s10270-012-0... is also very good starting point.


👤 standyro
IMO Ruby on Rails is one of the most successful uses of clever DSLs and metaprogramming. It probably created a few billion $ in value by enabling application developers to iterate quickly and skip template code that took 1000s of lines of Java. Learn how to do it in Ruby and you can make some libraries that do useful stuff for people who might definitely use it. It’s not the hippest language anymore but it has its niche.

👤 elamje
In my opinion Lisps - racket, scheme, Clojure, etc are the best way to do meta programming.

The code is stored in primitive data structures and is available to edit at runtime which is something that isn’t an easy thing to implement in a Lang like java or C#


👤 matijash
You might want to take a look at Haskell (Template Haskell) or Lisp/Clojure macro system. I haven't used Lisp yet, but I am working in Haskell currently. Here is a presentation that illustrates code generation in Haskell well, although it requires some Haskell knowledge: https://www.slideshare.net/kizzx2/template-haskell-tutorial

Haskell is also a good choice for writing DSLs and embedded DSLs.

Do you have a specific problem you would like to solve?


👤 shoo
Having a concrete problem or concrete project can help to focus attention. The "DS" of "DSL" is "domain-specific". So, what's your first target domain? Maybe your end goal is building some general machinery that is "domain agnostic" and can implement DSLs etc for multiple domains... but to get started it might be helpful to figure out what a good specific approach is for one particular domain, and then a second, and then a third.

👤 seisvelas
Racket has already been mentioned in this thread, but I think https://beautifulracket.com/ deserves a special mention. It is a diamond of programming literature and fabulously teaches the topic of language oriented programming in a language designed for that purpose.

I recently made a SQL for web dev in Racket and it was astonishingly easy.


👤 ragebol
Take a look at Jetbrains MPS. Cool things is that it uses a projectional editor, so you can have your DSL even be expressed in tables and other non purely text representations.

👤 verdverm
Max,

I have a number of references for you and a project you may like to check out.

Send me an email (in my HN profile) so I don't forget to get back to you, away from computer currently.


👤 PopeDotNinja
Ruby is good for DSLs. Maybe Elixir, too. Honestly, I don't like the brevity. Magic is great until your have to debug it.

👤 andrei_says_
Metaprogramming Ruby is a great book.