
Ask HN: How to get started with DSLs and meta-programming? - hans1729
Hello,<p>for quite a some time, I wanted to get started with these areas. Now I have some time on my hands, but I don&#x27;t really know where to look, or frankly, what exactly to look for.<p>My goal is to &quot;teach my machine to program for me&quot; (I hope you get the gist in the context of this posts title).<p>What do I want to look for? What prerequisites should I consider? ...<p>Thanks in advance,<p>Max
======
CyberFonic
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](https://modeling-languages.com)
is rather useful. The article:
[https://scihub.bban.top/https://doi.org/10.1007/s10270-012-0...](https://scihub.bban.top/https://doi.org/10.1007/s10270-012-0261-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#

~~~
quickthrower2
Yes lisps are meta programming. You won’t need to write a parser or code
generator, just transform your dsl into code.

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

