News for hackers. Stuff that matters.
Re:Red Programming Language by 90s_dev on Tuesday May 20, 2025 @07:04PM (#44046805)
No, an API uses existing rules, but a DSL uses its own ad hoc rules.

GP is right. Don't make DSLs, make APIs, which are:

* More composable

* More reusable

* More simple to reason about

* More natively supported

* More portable

* More readable

* More maintainable

Re:Red Programming Language by tuveson on Tuesday May 20, 2025 @08:06PM (#44047123)
There are plenty of places where it makes more sense to use DSLs (or where they’re flat-out required). SQL and regex both spring to mind. Pretty much any HTML templating language is simpler to use than concatenation a bunch of strings together. JSX is usually easier read than directly calling React functions directly. A line of a shell script can be much nicer (and more portable) than 20 lines of a more general purpose language.

Those are things that spring to mind that I think are unequivocally DSLs, but if you’re willing to consider markup languages as DSLs, the list could get a lot longer.

Re:Red Programming Language by 90s_dev on Tuesday May 20, 2025 @08:27PM (#44047230)
Most people think of DSLs as a language you can create within a language. All the things you named are either entire languages themselves like HTML, SQL, and the shell family, or formal extensions of existing languages like JSX. A DSL would be something you could create inside JS tagged literals or Ruby.
Re:Red Programming Language by ChadNauseam on Tuesday May 20, 2025 @08:31PM (#44047256)
I don't think of DSLs as strictly being embedded in another programming language. The term I would use for that is "eDSL", short for Embedded Domain Specific Language. See: https://wiki.haskell.org/Embedded_domain_specific_language
Re:Red Programming Language by fuzztester on Tuesday May 20, 2025 @09:00PM (#44047378)
Martin Fowler on DSLs, including internal and external DSLs:

https://martinfowler.com/books/dsl.html

https://martinfowler.com/dsl.html

Also see:

https://en.m.wikipedia.org/wiki/Domain-specific_language

including the References section.

Re:Red Programming Language by tangus on Tuesday May 20, 2025 @11:44PM (#44048082)
I've seen it. Sometimes a DSL is more readable than trying to shoehorn control flow into method calls (".then().catch()..."). Or see C#'s LINQ.
Re:Red Programming Language by kloop on Wednesday May 21, 2025 @12:18AM (#44048224)
> Or see C#'s LINQ.

This might be one of the rare times it's worth it. The C# team alread has the experience and tooling to maintain a language. Maintaining a DSL might be a reasonable choice for them.

It's rarely a good idea for app or library devs to make a similar decision.

Re:Red Programming Language by satoru42 on Wednesday May 21, 2025 @01:46AM (#44048618)
Yes, this reminds me of meta-programming in languages like Python, it's useful if you want to create a framework like Django, but if you work on products, chances are good you should not use it.
Re:Red Programming Language by vidarh on Wednesday May 21, 2025 @03:18AM (#44049089)
An API creates its own ad hoc rules too. They just don't change the grammar.

In languages where the grammar is sufficiently flexible, the distinction all but disappears, but even in languages where the grammar is rigid and API's stand out like a sore thumb, the API itself still creates a new rule-set that you need to learn.

You can choose to not call that a new language all you want, but the cognitive load is still there.

Re:Red Programming Language by binary132 on Wednesday May 21, 2025 @10:31AM (#44051860)
An API (as people usually mean by it, anyway…) is really just a simple grammar for the creation and manipulation of objects in the system. Those objects still have types and properties just like any other object, but they tend to be implicit and unreliable. A good DSL is just a more abstract and implicitly verb-oriented API. For example, Lua DSLs can resemble something almost like a sort of typed or tagged DDL. Translating that into an “API” just adds more clumsy legwork to achieve the same outcome.
Re:Red Programming Language by vidarh on Wednesday May 21, 2025 @10:55AM (#44052143)
Agreed - I was tempted to make the same claim that it is still a grammar, but decided against it as I suspected it'd get in the way of making the point. You're 100% right you can write a grammar for an API as well.