Abusing Proxies for DSLs
mcluck90.github.io
mcluck90.github.io
Why would you want to use this? I'm not sure.
Unfortunately one of the applications that immediately comes to mind is obfuscation.
I did a bit of JS work many years ago, before the whole "framework craze" and massive amount of churn started, and looking at the code written in it now, it almost feels like they're trying to compete on complexity with languages like C++.
repository.findBy<Property>()
That's one example of a real use that isn't just making life difficult for whoever comes after you.Not that there isn't a benefit from reducing things to the language you use to reason about the overall problem, and the language used to implement it. In large, whether you create a "DSL" or not, you almost always move to doing things in terms of the API you are using. Effectively making it a language. Taking a little more deliberate control does seem nice.
That said, I have found benefit in keeping fewer abstractions around. This is especially true as I am supporting an API. Don't hide that API from anything you do. Too easy to hide warts in it that you might otherwise fix.
That's pretty much the definition of https://en.wikipedia.org/wiki/Inner-platform_effect
Almost every story about a "business rules engine" I've heard was that it eventually turned into an odd Turing-complete programming language, and it'd be simpler to just write the same code in the original language.
The author does eventually define DSL, but it's pretty confusing until then.
-- Martin Odersky