February 2019

Diagrammatic Programming

We all carry smartphones in our pockets that are more powerful than a mainframe computer 50 years ago. At the same time, the way in which we program has hardly evolved at all. We're still writing text files using editors that are essentially just glorified typewriters. We have gotten so used to this, that most people think anything that doesn't look like esoteric text on a dark background, isn't "real" programming. But is this really the best medium for programming?

People are diagrammatic thinkers. When we sketch out an idea on the back of a napkin, we draw a diagram. Diagrams combine text, drawings and images in order to communicate in a way that none of them could do in isolation. In Field you program by drawing diagrams. The diagrams are not just sketches for the code, they are the code.

How is this different?

Of course, this is not an entirely new idea, there are other visual programming languages out there. Most commonly, when people say visual programming languages, they're talking about dataflow languages. In a dataflow language a program is described as a network of nodes through which data flows from node to node. People often assume that because the language is "visual", it is inherently easier or more intuitive to use. I would argue this is not the case, dataflow languages are often just as (if not more) obtuse and confusing as text based languages. And although they work well enough for simple programs, things quickly become messy and turn into visual spaghetti. In fact, most programmers agree that these node based languages are not much of an improvement.

Field takes an entirely different approach. In Field, a diagram is a graphic that describes a small part of your program. Diagrams consist of elements and relations arranged according to some organizing principle. Each of these individual diagrams can only describe a limited amount, but diagrams are composable. That is, diagrams can reference each other, or you can use one diagram as an element in other diagram. By doing this you create a patchwork of diagrams that together form a whole program. This means there is no singular way of visualizing the whole program. Different aspects of the program have different interfaces. Whether it's structure, process, logic, or changes over time, each aspect has its own unique way of being displayed and edited.

What would this actually look like?

As an example, let's create a simple todo list app. A todo list consists of a basic data-structure. We could draw this as a table.

The app also consists of a user interface. The way to represent this is obvious, because it is already visual.

Finally, we need to define what happens when we click the various UI elements. These are different actions that get triggered by events.

As you can see, I have now described a full MVC application using only three diagrams. The whole program fits on one screen.

So what?

If this doesn't seem earth-shattering to you, that's a good thing. It means you understood it immediately with only very minimal explanation, try that with javascript.

Unlike most programming languages, Field is actually not a general purpose language. Rather, you could think of it as a collection of smaller domain specific languages, which you combine to create a full program. This has several advantages:

Firstly, it makes complexity manageable. Programming is complex because everything can be looked at from different perspectives, things always exist in multiple contexts. Avoiding spaghetti code requires a good deal of experience thinking about "architecture". Diagrammatic programming splits things up along naturally occurring boundaries, good architecture is built in by design. It has different views for low and high level details, and shows you how things are composed together, which makes things easy to understand both in isolation and as a whole.

Secondly, it makes learning and collaboration a lot easier. You don't have to read the whole documentation before being able to start. Because most diagrams are much more simple and constrained than a whole language, they are very quick to pick up in isolation. This means you can start using Field the second you open it, and learning flows naturally as you explore and try to do more complicated things. Programs can be built collaboratively by people with different levels of experience and with backgrounds in different domains, each programming in a "language" that maps naturally onto their worldview.

Thirdly, the real power of diagrams lies in the idea of reflection. If you think about it, a todo list is actually also a kind of diagram. Field allows you to create new types of diagrams, diagrams you can then use to program more effectively. In Field, you solve problems by first creating a language that allows you to express it in a natural way.