Over a million developers have joined DZone.

Projectional Editing: The Future of Programming

DZone's Guide to

Projectional Editing: The Future of Programming

Learn about the Projectional Editor technology for programming, how it's being used to create domain-specific languages, and more.

· DevOps Zone ·
Free Resource

Discover how quick and easy it is to secure secrets, so you can get back to doing what you love. Try Conjur, a free open source security service for developers.

We have been taught for many years how programming should be done. Have you ever stopped for a second and questioned whether perhaps there is a better way?

In the beginning, programming was done in absolute binary. For years this was the only way to do it. It was only later that the Symbolic Optimal Assembly Program (SOAP) was introduced. For old developers, using assembly was “sissy stuff” and a real programmer would not waste machine capacity on doing the assembly.[1]

Developers had an easier way to code right in the front of their eyes, but a lot of them still refused to see it.

It was a similar story in 1957 when John Backus and his team created Fortran. The community was again skeptical that this new method could outperform assembly. Old generations stuck to their old ways.

Looking back now, it seems like the decision to change technology should have been clear, but at the time it was not. Nowadays, more and more developers are receptive to new technologies, but it is hard to change the fundamental principles with which programmers were taught.

Now, we again have a unique technology before us called Projectional Editing. Projectional Editing is not a new technology; back in 2008, Martin Fowler was already talking about it. JetBrains MPS is already using this technology for its language workbench to create domain-specific languages.

A projectional editor allows the user to efficiently edit the abstract syntax tree (AST) representation of the code. It can mimic the behavior of a text editor for textual notations, a diagram editor for graphical languages, a tabular editor for editing tables, and so on. The user interacts with the code through intuitive on-screen visuals.

In parser-based approaches, users use text editors to enter character sequences that represent programs. A parser then checks the program for syntactic correctness and constructs an abstract syntax tree (AST) from the character sequence. The AST contains all the semantic information expressed by the program, i.e. keywords, and the purely syntactic aspects are then committed.

In projectional editors, the process happens the other way around: as a user edits the program, the AST is modified directly. This is similar to the Model-view-controller (MVC) pattern where every editing action triggers a change in the AST.

When editing a UML diagram, for example, users don't draw pixels onto a canvas for an "image parser" to read the drawing, parse it, and then create the AST. That would be way too limiting to what you can draw so that the engine would understand. Rather, the editor creates an instance of a Class as you drag a class from the palette to the canvas. A projection engine then renders the diagram, in this case drawing a rectangle for the class. You can then re-arrange visual elements on the screen without changing the meaning of your diagram.

This approach can be generalized to also work with text editors. Every program element is stored as a node with a unique ID (UID) in the AST. References are based on actual pointers (references to UIDs). The AST is actually an ASG, (an abstract syntax graph), from the start, because cross-references are first-class rather than being resolved after parsing. The program is then persisted to disk as XML, but this process is transparent to the user.

Avoiding the parser provides users with two more benefits:

  1. Detaching the notation from the persistence format of the code enables multiple notations to be defined for a single language. The users can then interact with the code through one notation, and use another notation to debug, review code, or resolve merge conflicts.

  2. Languages can be modularized, and users can then combine languages that they want to use in their programs. The projectional editor easily resolves any ambiguities in language definitions.

As part of the new IT industry generation, we have to question the status quo and dogmas established by the old generations. We should not settle for less, we need to be our own critics on everything from UI element to fundamental statements of programming. Projectional Editing is here and we can either choose to ignore it or seize it for all its worth.

If you are still curious about Projectional Editing you can join the JetBrains MPS webinar which will take place September 19, 4:00 PM - 5:00 PM CEST. Register here.

Conjur is a free open source security service built by DevOps engineers. With integrations with all your favorite tools and an easy way to secure secrets, it's a no brainer. Come check it out!

domain specific language ,dsl ,devops ,programming ,code editor ,code editing

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}