1.4 Let’s begin.

1.4.1 What is a Program?

Generally, a program is a set of instructions which can be executed by a computer.. Typically a program will take some input from the user and perform a specific task. In Excel if you write the number 1 in cell A1, and then in any other cell =A1+2, excel’s compiler will process those instructions and display 3.

Below is a complete list of text editors that have support for Hoon syntax highlighting — an important tool for any programming language. For each of these editors, you’ll need to download the editor and then you’ll need to install some additional syntax-highlighter package. The process for adding Hoon support differs for every editor. For most newbie-friendly text editors, this is easily accomplished from within the editor itself, and you’ll learn how to do so following a newbie tutorial for that editor.

If you are brand new to programming, don’t think too much about which editor to use; any of the newbie-friendly options will suit you.

1.4.2 How we will display things

Adding the usual “” or () around elements of code that we usually would in text content can be confusing, so we felt that it was important to state outright how we are going to indicate things in this document. When there is user input or code or results displayed, we will not use any punctuation or symbols that do not relate to that code. We will utilize the following annotation elements:

this color and font – when we want to show code or something you will input

this color – when you will be entering something custom into the code such as your choice of a variable name (called a “face” name in Hoon), or if you needed to substitute “sampel-palnet” (note: ship names have syllables that are always consonant-vowel-consonant, so this is the accepted spelling for the arbitrary ship name “sample planet” in the ship naming convention) for your ship’s name – like “rabsef-bicrym” – it will look like this:

./urbit sampel-palnet -p 23456

this color – when we want to indicate a result that is displayed

this color – to indicate something that you cannot enter, or an error in code

Very basic ways to think about how to give instructions to a computer.

A common trope of introductory programming classes is an assignment to write instructions for making a peanut butter and jelly sandwich that even someone who had never seen a sandwich before, let alone a PB&J, could follow. This seems simple, but is much more complex than you might think. You can imagine doing this now, but I’d like to cut to the chase and talk about the common errors made by students in this assignment:

It will not do, to simply say “take bread, add peanut butter, add jelly, and add another bread.” If you’ve done this experiment before you know that the teacher will take a whole loaf of bread and stack a jar of peanut butter on it, and so on.

The point of the PB&J exercise is to explain to the student that computer programs are read by “naive” readers (the computer which doesn’t have any preexisting context or understanding of the world) and are interpreted literally. Becoming an effective programmer requires a solid feel for the extent to which one needs to be specific for a given programming language (i.e. the ways in which that language is “naive”) and the very precise rules for entering commands – called the syntax of the language. It will take some time, but when you get those under your belt you will have an intuitive understanding of how that computer language “thinks” and how you will need to interact with it.

Because of this computer naivety, instructions for our computers must therefore be laid out precisely, in full detail, with every step super clear and in meticulous order.

To return to our introductory exercise, the PB&J instructions should be more like:

  1. Take a bag of bread from the counter
  2. Open the bag of bread by un-twisting the twist-tie
  3. Remove two single slices of bread, ignoring the heel
  4. Place the single slices of bread flat on a plate
  5. Re-close the bag of bread by twisting the twist tie around the loose end of the bag
  6. Place the bag of bread out of your way, on the counter.
    and so on…

Precise and orderly instructions written as above provides the naive reader (our metaphor for a our naive computer) a series of very clear steps to follow to translate input (a bag of bread, a jar of peanut butter, a jar of jelly) into output (a PB&J).

The input -> output pipeline is, in fact, the program. One of the simplest programs we can imagine is a “Hello World” program, written in the BASIC computer programming language (a hello world program is an output only program that new users generally learn first in a given language – it simply prints “hello world” on the user’s interface). Even in this simplistic language, and this very simple program, we can see that we must provide very specific instructions to the computer to get what we want.

Here is our simple Hello World program written in BASIC:

10 PRINT “Hello, World!”

20 END

We see two main things from this

  1. We are telling the computer what to do on line 10 (easily human-readable as “Computer, print the words Hello World!”).
  2. We tell the computer where to end – this may not be immediately obviously important, but it will come to be critical in our study of hoon.