Building User-Friendly DSLs

Book description

Craft domain-specific languages that empower experts to create software themselves.

Domain-specific languages put business experts at the heart of software development. These purpose-built tools let your clients write down their business knowledge and have it automatically translated into working software—no dev time required. They seamlessly bridge the knowledge gap between programmers and subject experts, enabling better communication and freeing you from time-consuming code adjustments.

Inside Building User-Friendly DSLs you’ll learn how to:

  • Build a complete Domain IDE for a car rental company
  • Implement a projectional editor for your DSL
  • Implement content assist, type systems, expressions, and versioning language aspects
  • Evaluate business rules
  • Work with Abstract Syntax Trees
  • Reduce notated DSL content in concrete syntax into abstract syntax

Building User-Friendly DSLs takes you on a carefully-planned journey through everything you need to create your own DSLs. It focuses on building DSLs that are easy for busy business experts to learn and master. By working through a detailed example of a car rental company, you'll see how to create a custom DSL with a modern and intuitive UI that can replace tedious coding activities.

About the Technology
Here’s the central problem of software development: business users know what they need their apps to do, but they don’t know how to write the code themselves. As a developer, this means you spend a lot of time learning the same domain-specific details your user already knows. Now there’s a way to bridge this gap! You can create a Domain-Specific Language (DSL) that empowers non-technical business users to create and customize their own applications without writing any code.

About the Book
Building User-Friendly DSLs teaches you how to create a complete domain-specific language that looks and works like a web application. These easy-to-use DSLs put the power to create custom software into the hands of business domain experts. As you go, you’ll cover all the essentials, from establishing structure and syntax of your DSL to implementing a user-friendly interface.

What's Inside
  • Implement a projectional editor for your DSL
  • Work with Abstract Syntax Trees
  • Evaluate business rules


About the Reader
For developers with JavaScript and web development experience.

About the Author
Meinte Boersma is a senior developer and an evangelist of model-driven software development and DSLs.

Quotes
If you want to make your non-developer colleagues 10 times more productive, this is the book for you! You would be hard-pressed to find any skill that would have a bigger impact.
- Federico Tomassetti, Strumenta

A unique source of insight into state-of-the-art DSL tooling. Effectively combines bird’s-eye-view explanations with practical examples.
- Václav Pech, JetBrains

A down to earth approach to developing DSLs that’s easily accessible to all JavaScript developers.
- Jos Warmer, DSL architect

Guides the reader through a simple framework based on web technologies, touching on important aspects of DSL implementation along the way.
- Markus Völter, language engineer

Table of contents

  1. copyright
  2. contents
  3. Building User-Friendly DSLs
  4. dedication
  5. foreword
  6. preface
  7. acknowledgments
  8. about this book
  9. about the author
  10. about the cover illustration
  11. 1 What is a domain-specific language?
    1. 1.1 A business case: A car rental company
    2. 1.2 Using a DSL-based approach for software development
      1. 1.2.1 The design of the Domain IDE
      2. 1.2.2 The architecture of the Domain IDE
      3. 1.2.3 What we’ll be doing in this book
    3. 1.3 Why use a DSL-based approach for software development?
      1. 1.3.1 Empowering the domain experts
      2. 1.3.2 Improving the efficiency of the software development process
      3. 1.3.3 New possibilities
      4. 1.3.4 Criteria for adopting a DSL-based approach
    4. 1.4 What is a DSL?
      1. 1.4.1 A DSL’s notation
      2. 1.4.2 A DSL’s structure
      3. 1.4.3 A DSL’s meaning
      4. 1.4.4 A DSL’s constraints
  12. 2 Representing DSL content as structured data
    1. 2.1 Establishing an object-relation diagram notation for structured data
    2. 2.2 Going from concrete to abstract syntax
  13. 3 Working with ASTs in code
    1. 3.1 Turning ASTs into code
      1. 3.1.1 Encoding containment relations
      2. 3.1.2 Encoding reference relations
    2. 3.2 Interacting with ASTs
      1. 3.2.1 Accessing concept labels and settings’ values
      2. 3.2.2 Recognizing AST and reference objects
    3. 3.3 Traversing ASTs
      1. 3.3.1 The general recipe for DFTT
      2. 3.3.2 Example: Counting the leaves of an AST
      3. 3.3.3 More about ASTs
  14. 4 Projecting the AST
    1. 4.1 Preparing the implementation of the projection
    2. 4.2 Implementing the projection iteratively
      1. 4.2.1 Projecting record types
      2. 4.2.2 Projecting attributes
      3. 4.2.3 Projecting the initial values
  15. 5 Editing values in the projection
    1. 5.1 Changing names
      1. 5.1.1 Starting the editing
      2. 5.1.2 Using edit state
      3. 5.1.3 A reactive architecture for projectional editors
      4. 5.1.4 Reacting to change with MobX
      5. 5.1.5 Stopping the editing
      6. 5.1.6 Updating the AST
    2. 5.2 Changing the value of a number object
    3. 5.3 Choosing the type of an attribute
    4. 5.4 Choosing an attribute for a reference
  16. 6 Editing objects in the projection
    1. 6.1 Adding new objects to the AST
      1. 6.1.1 Adding an attribute
      2. 6.1.2 Adding an initial value
    2. 6.2 Selecting objects
      1. 6.2.1 Selecting an attribute
      2. 6.2.2 Deselecting an attribute
      3. 6.2.3 Selecting and deselecting any object
    3. 6.3 Deleting objects
      1. 6.3.1 Deleting initial values
      2. 6.3.2 Deleting attributes
      3. 6.3.3 Deleting any object
  17. 7 Implementing persistence and transportation of ASTs
    1. 7.1 Implementing and using a simple backend
    2. 7.2 Serializing an AST
    3. 7.3 Deserializing an AST
    4. 7.4 Making an AST observable during deserialization
    5. 7.5 Implementing save functionality
  18. 8 Generating code from the AST
    1. 8.1 Integrating the build system with the software development process
    2. 8.2 Using a reference implementation
    3. 8.3 A Runtime for Rental
    4. 8.4 Implementing a code generator using templates
      1. 8.4.1 Iterating from reference source to template
      2. 8.4.2 Composing template functions
      3. 8.4.3 Indenting declaratively
      4. 8.4.4 Finishing the code generator
      5. 8.4.5 Alternative approaches for writing templates
  19. 9 Preventing things from blowing up
    1. 9.1 Preventing failures by adding constraints
    2. 9.2 A template case: Dealing with an attribute without a name
      1. 9.2.1 Constraint strategies
      2. 9.2.2 Implementing the constraints checker
    3. 9.3 Dealing with all attribute-related faults
      1. 9.3.1 An attribute without a type
      2. 9.3.2 An attribute with an initial value “with holes”
      3. 9.3.3 Related attributes with unequal types
      4. 9.3.4 Sorting attributes according to dependency order
      5. 9.3.5 Detecting cycles of attributes
      6. 9.3.6 Attributes with too similar names
  20. 10 Managing change
    1. 10.1 Managing DSL content change
    2. 10.2 Categorizing and charting coupling
    3. 10.3 Changing the DSL
      1. 10.3.1 Versioning the Domain IDE
      2. 10.3.2 Changing the DSL’s structure
      3. 10.3.3 Deprecating concepts and properties
      4. 10.3.4 Changing a DSL key aspect other than structure
  21. 11 Implementing expressions: Binary operations
    1. 11.1 Representing expressions as DSL content
      1. 11.1.1 Changing the structure
    2. 11.2 Changing the projection
    3. 11.3 Changing the runtime
    4. 11.4 Changing the code generator
    5. 11.5 Postscript: Expressions in general
      1. 11.5.1 Characterizing expressions by arity
      2. 11.5.2 Compositionality and expressiveness
      3. 11.5.3 Characterizing expressions by operator
  22. 12 Implementing expressions: Order of operations
    1. 12.1 Evaluating and building expression ASTs
    2. 12.2 Adapting the projection for operator precedence
    3. 12.3 Adapting the projection for associativity
    4. 12.4 Using side-transforms to improve editing
  23. 13 Implementing a type system
    1. 13.1 Computing types of expressions
    2. 13.2 Implementing type checking constraints
    3. 13.3 Representing types as objects
  24. 14 Implementing business rules
    1. 14.1 Extending the DSL with business rules
      1. 14.1.1 Defining business rules
      2. 14.1.2 Writing logical expressions
      3. 14.1.3 Defining consequences
    2. 14.2 Implementing the business rules in the Runtime
      1. 14.2.1 Running each business rule separately
      2. 14.2.2 Combining effects
      3. 14.2.3 The execution model of business rules
      4. 14.2.4 Changing the Runtime
      5. 14.2.5 Generalizing the implementation
    3. 14.3 Generating the business rules’ code
      1. 14.3.1 Identifying affected attributes
      2. 14.3.2 Generating and using the rulesEffects method
      3. 14.3.3 Adapting the UI of affected attributes
  25. 15 Some topics we didn’t cover
    1. 15.1 Parsing, and textual DSLs
    2. 15.2 Using the word “model”
    3. 15.3 Using terms with the prefix “meta”
    4. 15.4 Using language-oriented tooling
      1. 15.4.1 Using a language workbench
      2. 15.4.2 Implementing the example DSL with MPS
      3. 15.4.3 Using language-oriented frameworks
  26. appendix A Setting up the development environment
    1. A.1 Putting together a development environment
      1. A.1.1 Choosing between a local or online development environment
    2. A.2 Setting up a local development environment
      1. A.2.1 Installing Node.js
      2. A.2.2 Installing Visual Studio Code
    3. A.3 Using a web IDE
      1. A.3.1 Using Gitpod.io
    4. A.4 Setting up a repository for JavaScript development
    5. A.5 Using the Node.js REPL
    6. A.6 Running development tools
  27. appendix B Implementing a Transparent Functional Reactive frontend
    1. B.1 Establishing an idiom for JavaScript code
      1. B.1.1 No semicolons to separate statements
      2. B.1.2 Indentation/whitespace conventions
      3. B.1.3 Using const declarations for values wherever possible
      4. B.1.4 Defining functions as const declarations using arrow function expressions
      5. B.1.5 Exporting members from files
      6. B.1.6 Object destructuring
      7. B.1.7 Importing members
      8. B.1.8 Favoring plain objects over classes
      9. B.1.9 Using the spread syntax
      10. B.1.10 Using template literals
      11. B.1.11 Unit testing
    2. B.2 Setting up a basic frontend with React and Parcel
    3. B.3 Using React components to implement a frontend
      1. B.3.1 Using destructuring to receive component parameters
      2. B.3.2 Using application state
      3. B.3.3 Nesting component calls
      4. B.3.4 Mapping an array over a component
      5. B.3.5 Using an and operator for conditional content
      6. B.3.6 Combining CSS classes
    4. B.4 Using MobX to react to changes
      1. B.4.1 Installing MobX
      2. B.4.2 Marking objects as state
      3. B.4.3 Marking components as reactive
      4. B.4.4 Marking functions as actions
      5. B.4.5 Marking classes as stateful
      6. B.4.6 Putting everything together

Product information

  • Title: Building User-Friendly DSLs
  • Author(s): Meinte Boersma
  • Release date: November 2024
  • Publisher(s): Manning Publications
  • ISBN: 9781617296475