Notional Machines

what does it mean to learn a programming language and runtime environment?

One workable answer is to learn a "notional machine".

Just a fancy way of saying that you are comfortable using words and diagrams to explain what is happening inside of the computer at any point in your program's execution. A series of

  • visualizations
  • diagrams
  • refactoring techniques
  • vocabulary

That are accurate but manageable; correct enough that you can use them to predict program state, debug your projects, and accurately translate between diagrams & code. But not so precise that you get lost in low-level implementation.

A very important feature of a notional machine is that it doesn't use analogies. It builds new intuitions based on how computers work, instead of building on old intuitions you already have about how the rest of the world works.

An easy danger when learning to program is to use analogies for familiarity. This is especially dangerous because programming languages & computers are not like other things you know! Any intuitions built off of previous experience will be misleading and can make learning more difficult in the long run.

Using a common set of visualization tools, and correct vocabulary from day 1 is super important. Building up a shared and correct understanding is only realistic when you, your peers and your coaches all discuss the same visuals with the same vocabulary.

These diagrams and visualizations will expand and become more detailed as you learn more about your programming language and environment. Take JavaScript for example:

  1. The first JS notional machine you will learn includes only what takes place on the callstack - variables, functions, types/operators, control flow, data structures, to name a few.
  2. Next is the event loop. To understand asynchronous JavaScript, nothing you learned about the CallStack changes. But you will need to add a heap and a queue to your JavaScript notional machine.
  3. Browsers are a ubiquitous runtime environment for JavaScript. Besides having a JS callstack & event loop, browsers have other components to incorporate into their notional machine including the DOM, local storage, and networking functionalities.
  4. Another is Node.js. Node.js also has a callstack, a heap, and a queue. But it also has modules, file system access, and can open a port on the internet. These add to but do not change what you have already learned about JavaScript works.

Your brain will construct an understanding of how JS and these other programming environments work whether or not you intentionally guide it, it's what brains do. As great as this sounds it is actually quite risky. Web Development is very complicated and it is very easy to come up with explanations that work for simple projects but are not accurate. You won't notice at first, but as soon as you try to move on you will find it nearly impossible to understand what's going on, and you will be unable to effectively plan or debug your projects. Unlearning and relearning how environments like the Browser or Node operate is difficult and will take much more time than learning correctly from the beginning.


References