liveBook · Manning

Reference implementation

As explained in Building User-Friendly DSLs

A small, separate, functional software system that demonstrates the intended architecture, conventions, and representative functionality of a larger system.

A reference implementation is a separate, small, functional software system that serves as a focused example or template for a larger Runtime. It follows the Runtime’s chosen architecture, technological layers, coding style, conventions, build configuration, and representative functionality, while remaining independent from the Runtime itself. section 8.2

Build it before the code generator. This separates two difficult tasks: first establish how the Runtime is organized and which business-knowledge code can come from the AST; then turn the established implementation into generated code. The reference implementation becomes the starting point for the build system and for iteratively deriving code templates. section 8.2 section 8.5

A useful reference implementation is:

  • Functional and separate from the Runtime. section 8.2
  • Complete enough to work through the selected architecture and technological layers. section 8.2
  • Consistent with defined coding style and conventions. section 8.2
  • Representative of the functionality the Runtime must support. section 8.2
  • Small enough to understand, build, run, deploy, change, and validate quickly. section 8.2

For DSL-based generation, the business-knowledge portion must be expressible as DSL content. If that content can generate all corresponding business-knowledge code in the reference implementation, the same approach is likely suitable for the Runtime. Hand-written code remains for concerns the DSL cannot specify, alongside build configuration that assembles a deployable or runnable artifact. section 8.0 section 8.2

Rental Runtime

A compact Rental Runtime demonstrates the approach with a React form for one rental record. Its four fields represent a rental period, price before discount, discount, and price after discount. DSL amount and percentage values map to JavaScript Number values; a DateRange class represents the date range and prevents an end date before its start date. This working implementation supplies concrete code to parameterize later from AST information. section 8.3 section 8.5

Figure 8.4 The relation between the Runtime and reference implementation
figure

Compare the small reference implementation with the Runtime and identify the business-knowledge code intended for generation. section 8.2

Once the reference implementation is stable, derive template functions gradually by replacing fixed code fragments with expressions supplied from pieces of the AST. JavaScript ES2015 template literals and nested strings support template composition and readable, properly indented generated code. section 8.5

How Building User-Friendly DSLs covers it

How deep it goes
Defines required qualities and applies them to a complete React Rental Runtime, then outlines iterative template derivation.
Examples
Uses a React Rental form with amount, percentage, and date-range fields as the reference implementation.
What it assumes
Assumes a chosen Runtime architecture and DSL content whose business knowledge can be represented in an AST.
What you can do after
Build it from scratch as a small Runtime that can guide AST-based code generation.
How it connects
Connects Runtime architecture, DSL content, ASTs, code generators, template functions, and build configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.