Skip to content

Commit f352a84

Browse files
add yaml vs dsl
1 parent b5e91bf commit f352a84

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

website/blog/yaml-vs-dsl.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
author:
3+
- name: Herrington Darkholme
4+
search: false
5+
date: 2025-07-07
6+
head:
7+
- - meta
8+
- property: og:type
9+
content: website
10+
- - meta
11+
- property: og:title
12+
content: 'YAML vs DSL: comparison is subjective'
13+
- - meta
14+
- property: og:url
15+
content: https://ast-grep.github.io/blog/yaml-vs-dsl.html
16+
- - meta
17+
- property: og:description
18+
content: YAML and DSL are two different approaches to configure rule in structural search. The question "which is better" is largely subjective.
19+
20+
---
21+
22+
# YAML vs DSL: comparison is subjective
23+
24+
As stated in the [tool comparison](/advanced/tool-comparison.html#gritql), YAML configuration and DSL (Domain Specific Language) are two different approaches to configure rules in structural search. The question "which is better" is largely subjective.
25+
26+
However, recently I have received some feedback that YAML is __objectively__ not as good as DSL, and I would like to clarify some points.
27+
28+
29+
The original argument is quoted as follows:
30+
31+
> While I see you're trying to dismiss it as a preference, I see it as a fundamental blocker. ast-grep has effectively built a DSL inside YAML. This becomes pretty apparent from your documentation, where you have to extensively explain how pattern syntax works, how metavariables work, etc.. You have to see that arguments such as "it's just YAML, no new syntax to learn" aren't entirely true either. Now IMO, if you're creating a DSL anyway, you're better off doing it properly than to go halfway. With GritQL we get syntax highlighting for all the aspects of the DSL, which I think is a significant boost. I think GritQL queries are significantly easier to read than ast-grep's mix of DSL of YAML.
32+
33+
## Direct rebuttal to the argument
34+
35+
> effectively built a DSL inside YAML
36+
37+
This is a misunderstanding of DSL and abstraction. To model Abstract Syntax Tree (AST) manipulation, you will have to have some form of concepts, such as pattern, metavariable, etc. This is true for both DSL and YAML. You cannot cut more concepts out of the tool even if you have [Occam's razor](https://en.wikipedia.org/wiki/Occam%27s_razor).
38+
39+
ast-grep does support pattern. It is a concept to match a strcture that contains multiple AST nodes, which makes it easier to write a rule. You can use `kind`/`has`/`all` to simulate pattern matching. But it does not mean that ast-grep should cut the concept of pattern since it looks like a DSL. In fact, ast-grep's pattern is just one of its [atomic rules](/guide/rule-config/atomic-rule.html). It does not meant to be a special embedded DSL.
40+
41+
> your documentation, where you have to extensively explain how pattern syntax works, how pattern syntax works, how metavariables work
42+
43+
As stated before, pattern makes ast-grep users' life easier. Explaining how pattern works is necessary to help users understand how to write rules. This is not a sign of a DSL being necessary, but rather a sign of the limitation of pattern: it is not general enough to cover all cases, and you have to communicate to your users how pattern works in your system. For example, see this [tweet](https://x.com/hd_nvim/status/1941876968363798766) about how to write a pattern to match `functtion` declation in JavaScript.
44+
45+
(an [ad-hominen](https://en.wikipedia.org/wiki/Ad_hominem) note: it is ironic to see this argument from a tool without proper documentation. I cannot suspend my suspect whether the author has used pattern to write non-trivial rules at all.)
46+
47+
48+
> if you're creating a DSL anyway, you're better off doing it properly than to go halfway
49+
50+
This argument is a [slippery slope fallacy](https://en.wikipedia.org/wiki/Slippery_slope). Using pattern syntax does not mean that other rules should also be written in DSL. Again, pattern is just one of ast-grep's rules. ast-grep compose smaller rules to form more complex rules. ast-grep's rule system is not DSL based, but rather using YAML's key-value pair to represent rules. Using syntax in one rule does not imply that all rules should be combined in DSL.
51+
52+
Using one concept in your library, framework or tool does not imply that you have to design a whole new syntax for it. The similar comparison will be frontend frameworks. Some frameworks like React and Vue use [hook](https://react.dev/reference/react/hooks) or [signals](https://dev.to/this-is-learning/the-evolution-of-signals-in-javascript-8ob) to represent state changes. But using these building blocks does not grant the verdict to design a new language for your frontend framework. Even the most avant-garde company only introduces [new syntax](https://flow.org/en/docs/react/hook-syntax/) in JavaScript, not inventing a new language.
53+
54+
55+
> I think GritQL queries are significantly easier to read than ast-grep's mix of DSL of YAML.
56+
57+
This is a subjective opinion, instead of an fundamental blocker. The author failed to capture the difference between _"pattern syntax"_ and _"rule system"_. ast-grep's rule system is YAML based, so it is easier to write a [well-formed](https://en.wikipedia.org/wiki/Well-formedness) rule. Instead, DSL based rule system using their own syntax and can be more difficult to write a valid rule, especially for beginners.
58+
59+
We can also see using DSL is not subjectively better than YAML as well.
60+
61+
## Subjective Comparison of DSL

0 commit comments

Comments
 (0)