I've read comments stating that Scala's flexibility makes it easy for developers to write DSLs that are difficult to understand and reason about.
DSLs are possible because
- we can sometimes omit
.
and parentheses (e.g.List(1) map println
) - we can sometimes interchange
()
and{}
- we have implicit values, parameters, and classes (also conversions, which are now discouraged)
- there is a relatively small number of reserved symbols in the language (e.g. I can define
+
for my class)
and possibly other language features.
How can I avoid writing confusing DSLs ... what are the common antipatterns? Where is a DSL not appropriate?