vvvv / TeachingPatching

1 stars 0 forks source link

Collect visual examples/analogies/mental models to explain programming principles #10

Open jhnnslmk opened 4 years ago

jhnnslmk commented 4 years ago

Datatypes (Records/Class), Process, Statefulness, Collections, Loops, If-Regions, Observables etc.

I imagine these to look somewhat like what Anton did back then for i.e. Spreads: https://vvvv.org/documentation/spread-operations

gregsn commented 4 years ago

Let me leave some ideas without claiming to have found the right ones yet. There might be better ones...

Comparing records with classes: Records are like well actually records. Once pressed a vinyl record has some immutable information on it. This is it. Classes (i hate the name as it is on another more general level and doesn't relate to records in any way) are a bit like magnetic tapes. Alan Turing used tapes to explain his theoretical idea of a Turing machine. You don't need to throw away the tape, just overwrite what needs to get updated.

A process node is a small feedback system. A living entity like a cell. While operations can be compared to a chemical reaction (e.g. within a cell), a process is the whole system in a shielded safe shell, where certain mechanisms go on and on, repeating over time, changing its state and communicating with the outside world.

The idea of statefulness allows us to reason about the process, while statelessness only allows us to reason about a mechanism (like a chemical reaction, with its left side of the arrow and the right side of the arrow). When in a stateful context we can take more into account and can affect the state.

So we had music and biology comparisons. Here is another one:

A whiteboard allows me to scribble, erase and scribble again. It's a bit like changing the state of a mutable instance. While writing a letter only allows me to write something down once and when not happy to start over again. It's like creating several immutable instances whenever I want to change the state of a certain object (not so happy with this analogy because the process of writing the letter mutates it)

Now, where are these things happening?

It's a bit what process node with State Output are doing. They are managing an instance and depending on whether the type is mutable or not, they behave the one or other way. Note I am talking about the running program, not about the process of changing the code of these types. So I am only talking about feeding different data into the process node via input pins. This results in letters or a changed whiteboard, where the whiteboards' and letters' content is also influenced by the properties of the type and the inputs of the process node. So we can't draw what we want, which is not captured by the analogy. Maybe we should save the analogy for something that comes even closer (like being able to create and manage an anonymous datatype instance with a sort of process node, allowing us to adjust properties and mutability flavors on the application side.)

There is more to be said on what happens when we consume a record or class when calling an operation and outputting a new State Output. It's like the whiteboard and letter example only now these things get handed over via links. A whiteboard might feel too heavy to hand it over via links, which speaks against that analogy. But for now I stop to give room for more ideas.