๐Ÿงฌ
๐Ÿงฌ How Programming Languages Work ยท PL-101 ยท Session 5 of 6

Designing a Language (and Why You Might)

Building a language is one thing; designing a *good* one is another. And you don't need a general-purpose language โ€” small, focused 'domain-specific' languages are where custom languages really shine.

โฑ 9 min read๐Ÿ“… Updated 2026-08-08๐Ÿ“Š Tables, charts & examples

Knowing how to build a language is powerful; knowing why and what to build is what makes it useful. Most people will never design a general-purpose language to rival Python - and shouldn't try. The real payoff is smaller and sharper: domain-specific languages (DSLs), little languages tailored to one problem, where a custom language genuinely beats a library. This session is about language design - what makes a good one, and where custom languages actually shine.

Small, focused languages win

You've likely used DSLs without thinking of them as languages: query languages, template languages, config formats, formula syntax. Each is a little language built for one job.

Domain-specific languageIts one job
A query languageAsk questions of data
A template languageGenerate text/HTML from data
A build/config formatDescribe how to build/configure
A formula languageExpress calculations (like a spreadsheet)

These win because they're shaped exactly to their problem - expressing a data query or a template is cleaner in a purpose-built little language than in general code. The stack even has examples: <a href='/stack/larztemplate'>larztemplate</a> is a template DSL, <a href='/stack/larzquery'>larzquery</a> a query-like interface, <a href='/stack/larzlogic'>larzlogic</a> a boolean-expression language. A focused language for a real problem is where custom languages earn their keep.

What makes a language good

Good language design is about the experience of the person writing in it - clarity, consistency, and fit to the problem.

๐ŸŽฏ
Design for the writer: make the common thing easy and the code read like the problem. A good language makes its intended use natural and readable - the code should look like a clear description of what you mean. It's consistent (similar things work similarly, few surprises), it makes the common cases simple, and it fits its domain so tightly that programs read almost like plain statements about the problem. That's exactly the design goal behind larzscript: because it's for money, pay $9 from customer to platform reads like what it does - the language is shaped to its domain. When you design a language, obsess over how the programs will read and feel to write, because that's the whole point of making a language instead of using a library.

Why build one at all

The honest answer: usually you shouldn't build a general language - but a small DSL for a real, recurring problem can be genuinely worth it.

Build a language when...Not when...
A problem recurs and needs its own clear notationA library or function would do
Non-programmers need to express somethingIt's a one-off
The domain has its own natural 'grammar'You just want to look clever
Existing tools force awkward expressionSimplicity would serve better

The bar is real value: a DSL is worth it when a focused notation makes a recurring problem dramatically clearer to express - for its writers, who may not even be programmers. Larzscript exists because 'money-native' is a real, recurring domain worth its own grammar. Most of the time, a good function beats a new language - but when a language is right, nothing else compares.

Design for the problem and the writer

  • Small domain-specific languages (DSLs) are where custom languages shine - queries, templates, configs, formulas.
  • Good design makes the common case easy and code read like the problem, consistently.
  • Larzscript is a DSL for money - shaped so pay X from A to B reads like what it does.
  • Usually a library is better - build a language only when a focused notation genuinely wins.

๐Ÿงฉ Do it with LarzOS

Turn this lesson into action with the exact free tools and AI workflows for the job:

๐ŸŽฏ Key takeaways

  • Most custom languages should be small domain-specific languages (DSLs) for one problem, not general-purpose rivals.
  • You already use DSLs: query languages, template languages, config formats, formula syntax - each a little language for one job.
  • Good design makes the common case easy and makes code read like a clear description of the problem, consistently.
  • Build a language only when a focused notation genuinely beats a library - as 'money-native' does for larzscript.

Frequently asked

What exactly is a 'domain-specific language' and how is it different from a normal language?

A domain-specific language (DSL) is a small programming language designed for one particular problem area (domain), as opposed to a general-purpose language (like Python or Java) designed to do anything. The difference is scope and focus: a general-purpose language aims to be capable of expressing any computation across all kinds of problems, so it has broad features and isn't specialised toward any one domain; a DSL deliberately narrows its focus to a specific kind of task and shapes itself tightly around that, trading generality for a much better fit to its one purpose. Because a DSL targets one domain, it can offer notation and constructs that make expressing things in that domain exceptionally clear and concise - clearer than you could achieve in a general language, precisely because it's not trying to also handle everything else. You've almost certainly used DSLs without labelling them as such: a query language for asking questions of a database is a DSL for data querying (it has notation shaped exactly for filtering, sorting, and selecting data); a template language for generating HTML is a DSL for producing text from data; configuration formats that describe how to set up or build something are DSLs for configuration; the formula syntax in a spreadsheet is a DSL for calculations; patterns for matching text are a DSL for text-matching. Each is a little language purpose-built for its domain, and each is more pleasant for its specific job than writing general-purpose code would be. The key distinctions from a general language: a DSL is smaller (fewer features, focused on its domain), specialised (its constructs map to domain concepts - a query language has 'where' and 'order by', a money language has 'pay' and 'wallet'), often more approachable for its domain (sometimes usable by non-programmers who understand the domain, like analysts writing queries or designers writing templates), and not intended for general programming (you wouldn't write a whole application in a query language). The value of a DSL is that within its domain, code reads almost like a direct description of what you want, because the language's vocabulary and structure are the domain's vocabulary and structure. That's why DSLs are where custom languages genuinely shine and where most people who build a language should focus: rather than building a general-purpose language to rival established ones (rarely worthwhile), you build a small, sharp language for a specific recurring problem where a tailored notation is a real win. Larzscript is exactly this - a DSL for the domain of money, with constructs (price, wallet, pay, paywall, subscribe) shaped so that money-handling code reads like plain statements about money, which a general-purpose language can't match for that domain. So a DSL differs from a normal (general-purpose) language by being deliberately specialised for one problem area, trading the ability to do anything for the ability to express one kind of thing exceptionally well - and that focus is its whole strength.

How do I know if a problem is worth building a language for, versus just writing a library or functions?

This is the crucial design judgement, and the honest default is that you usually shouldn't build a language - a good library or set of functions is simpler and sufficient for most problems - so the bar for a DSL being worthwhile is genuinely high and specific. Build a language (a DSL) only when a custom notation provides substantial value that a library can't, and here are the signals that suggest it might. First, the problem recurs and has its own natural 'shape' or grammar - if you're repeatedly expressing something in a domain that has recognisable patterns and vocabulary, a notation shaped to that domain can make expressing it dramatically clearer than general code with library calls. Second, the people who need to express things in this domain may not be programmers, or shouldn't have to write general-purpose code - a DSL can let domain experts (analysts, designers, business people) express what they need in terms they understand, which a programming library can't. Third, existing approaches force awkward, verbose, or error-prone expression - if using a library means lots of boilerplate or unclear code that a focused notation would make clean and obvious, that's a point for a DSL. Fourth, the domain genuinely benefits from its concepts being first-class - like money being a keyword in larzscript rather than library calls, so the code reads like and enforces the domain's rules. On the other side, prefer a library or functions when: the problem is a one-off or doesn't recur enough to justify building and maintaining a language; a well-designed function or set of functions would express it clearly (which is true for most problems); the users are programmers who are perfectly happy calling library functions; or you're tempted to build a language mainly because it seems impressive rather than because it genuinely serves the problem better (a real risk - building a language is a lot of work and adds complexity, so it must earn its place). The costs of a DSL are real: you have to build and maintain the language (lexer, parser, interpreter, error messages, tooling), users have to learn it, and it's another thing that can have bugs - so those costs must be outweighed by substantial gains in clarity, accessibility, or correctness for a recurring, valuable problem. A good test: would programs in this language be dramatically clearer and more natural than the equivalent library code, for a problem you'll express many times, possibly by non-programmers? If yes, a DSL may be worth it. If a library would serve nearly as well, or the problem isn't recurring and valuable enough, build the library - it's simpler and lower-risk. Also consider intermediate options: sometimes a well-designed library with a fluent, readable interface (an 'internal DSL' expressed within a general language) captures much of the benefit without building a separate language, which can be a lower-cost middle ground. The overarching principle is that a language is a heavyweight tool justified only by heavyweight value - a recurring, domain-shaped problem where tailored notation is a real, substantial win, often for non-programmer writers. Larzscript clears this bar because money-handling is a recurring domain with its own concepts where making them first-class provides real clarity and enforcement. Most problems don't clear it, and a library is the right, simpler choice. So default to a library, and reach for a DSL only when the specific, substantial benefits of a custom notation for a real recurring domain clearly outweigh the significant cost of building and maintaining a language. The skill is honest assessment of that trade-off, resisting the allure of building a language when a function would do, while recognising the genuine cases where a focused little language is the superior tool.

Session 5 of 6 complete

Next up: Build Your Own Language

Continue to Session 6 โ†’

Related lessons

More in this course

Course home → · Browse all courses →