Skip to content

dsl-course/mps-textbook-beginners

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Programming with JetBrains MPS — Textbook for Beginners

This document contains an outline of a textbook on JetBrains Meta Programming System (JetBrains MPS) being written by Mikhail Barash. The purpose of this document is to have a discussion on the content structure of the textbook with MPS community members.

The textbook is meant for those without any prior experience on JetBrains MPS or language engineering. The author has some experience in teaching courses on MPS, and this book is planned as an embodiment of the methodological approaches used in different teaching settings.

The structural unit of the book is a double-page spread, rather than a page. Each spread is a finished piece of information — it has self-contained material on a particular topic. Some topics span over several spreads, and in such cases each of the spreads is devoted to a single subtopic.

The textbook is divided into three parts:

This choice and order of the parts is explained by a desire to avoid burdening the reader with language engineering terminology (from our experience, even "AST" scares off beginners.) We start with known terminology – classes, interfaces, enumerations – and slowly revise key notions and ideas using "appropriate" terminology. Moreover, the choice of the parts reflects typical patterns for building a software language.

Here are some of the highlights of the content of the textbook.

  • As the intro text of each of the parts of the book is still a double-page spread, there is no explicit separation into parts for the reader.
  • The book starts with a general discussion on what a workbench is (not only language workbench).
  • At first, MPS is presented as a tool to define textual user interfaces. We start with familiar notions of classes, interfaces, enumerations, etc. and throught this part, we introduce their "counterparts" in MPS. For example, classes become concepts and so on.
  • Each of the three parts of the book has a running example that we develop from scratch until completition during the course of the corresponding part.
  • In the first part, we develop a textual UI for Invoice Calculator, introducing and showcasing necessary MPS notions.
  • We postpone as much as possible discussing language aspects. When we finally have to introduce aspects, we do not expose the reader to details unnecessary at a particular point. For example, discussion of Editor aspect tries to avoid making a big deal of projectional editing (see below). Actions aspect in not mentioned until the second part of the book, where it comes naturally in one of the examples.
  • We then discuss Intentions aspect and make a point about importance of domain-specific error support. We discuss an implementation of Invoice Calculator in Excel for comparison.
  • Code generation is discussed throught several spreads of the book, and we start with TextGen aspect, where we define a generator for Invoice Calculator that generates RTF files.
  • We continue with code generation with Generator aspect: we define a generator for Invoice Calculator to XML.
  • At this point we make an excursion to XML/XSLT and give a conceptual comparison of Generator aspect and XSL transformations.
  • We then continue with generating Java code with Generator. We deliberatly discuss Java code generation after RTF and XML to address a frequent opinion of the newcomers that MPS only allows generating Java code.
  • Projectional editing does often scary off beginners by its perceived "clumsiness" and limitations. That is why it is not "introduced" until this moment. We try to make the point that there is nothing special in the fact that MPS (only) supports projectional editing, by discussing that most of the functionality of a traditional text editor is replicated in MPS. Putting projectional editing to the backstage was a major decision we made about this book, and it still remains to see whether it makes a difference. We also discuss in details Actions aspect.
  • In the second part of the book, we use MPS as a modelling tool, i.e., we discuss the raison d'être application of MPS — implementation of domain-specific languages. Running example of this part is Entities language; we define code generators into Java, JavaScript/React and Excel/VBA. This selection of target languages is motivated by the need to communicate to the reader that MPS can be used to generate web applications as well as "legacy code".
  • We revise the metaphor of OOP counterparts in MPS that we introduced in the beginning of the first part, and encourage the reader to focus on notions used in language engineering.
  • We return again to code generation with Generator aspect, where we discuss in more details reductions, quotations, mapping labels, etc.
  • We then continue with type system and data-flow analysis for Entities language. By this time, the reader has implemented a tiny domain-specific language. Our goal here was to describe the development of a language from scratch within one "chapter". The second part is concluded by a discussion on evolution of Entities language and language migration in MPS.
  • The third part of the book is devoted to using MPS to extend baseLanguage — we introduce several extensions of Java, talk again about Actions, Constraints, and Generator aspects. We also discuss about extending Entities language.
  • We give an overview of language composition (reference, extension, reuse, embedding) and talk again about projectional editing and how it enables language composition. However, we do not go into further details on language reference/reuse/embedding because these topics, in our opinion, should be covered in a more advanced book.
  • For the same reasons, we do not discuss any of the MPS extensions, such as grammar cells or PlainTextGen.
  • We do not discuss testing. This is a drawback, but discussing this topic might complicate reader's perception of already non-trivial material. The purpose on the textbook is to give an introduction to MPS: we don't aim at preparing a reader for deploying a language. Another important topic that is left for a more advanced book is debugging.
  • We explicitly mark each spread of the book with "difficulty" level, suggesting several study paths for those interested in superficial acquaintance with MPS, those who already have some basic knowledge, or those who want to study more "advanced" topics.
  • Finally, because we revise MPS idioms, notions, and used terminology throughout the book, and because of the very layout of the book, some repetitions of the material are unavoidable.

Below we list the spreads of the book.

Spread # Topic
0 What is MPS?
1—2 MPS as a Tool for Textual User Interfaces
3—6 Object-Oriented Programming in MPS
7 Intentions and Quickfixes
8—10 Generating Text Output with TextGen
11 Generating XML Output with Generator
12—13 Generating Java Code with Generator
14—16 Projectional Editing: Pros and Cons
17—18 Tabular and Graphical projections
19 MPS as a Modelling Tool
20—21 Looking at Code Through MPS Prism
22—24 Entities Example
25—26 Scoping Rules and Constraints
27—29 Generating Java Code with Generator
30—31 Generating JavaScript Code
32 Generating VBA Code
33—34 Checking Domain Code: Type Systems
35 Checking Domain Code: Data-Flow Analysis
36 Evolution of Languages
37—39 MPS as a Tool for Extending Existing Languages
40 MPS in Practice

When Will the Textbook Be Ready?

Rough estimate is Q2–Q3 2020.

It takes a significant amount of time not only to prepare the content of a spread, but also to layout it in a proper and engaging way. Inspired by this, this and this, we try to use encyclopedia-style layout (only layout — not content), for example, with boxes for extra material, and so on.

The book will be published electronically and will be open-source: all spreads will be published in Adobe Illustrator format (layers preserved etc.) so that they could be (re)used for creating teaching materials.

About

Programming with JetBrains MPS - Textbook for Beginners

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published