What is code?

A short lesson about code and what programming is.

1:text

Code

Programming is all about writing text that we call code. This text is essentially a set of instructions that we can understand and work with efficiently. It will later be translated into a very specific set of instructions that the computer can understand and work with efficiently.

Note: Programming languages that are based on instructions are categorized as imperative and are, by far, the most common. But there are also languages which are declarative, that instead describe what the result should be - not how it should be accomplished. This course is only about imperative languages.

When we're programming, we're trying to tell the computer how to accomplish a task so that it can do the jobb for us. Programming is difficult because we first need to figure out how the problem can be solved, and then explain it to the computer exactly. And when we say exactly, we mean it.

The computer is an incredibly stupid device. Sure, it can remember millions of books and reproduce their contents verbatim faster than you can blink. It can multiply numbers larger than you can imagine in a fraction of a second. But it can't actually think on it's own.

What it can do is meticulusly follow the set of instructions it's been given, no matter the size or complexity, at a breathtaking speed without ever making a single mistake. But it will only ever do exactly what the programmer told it to. No more. No less.

2:quiz
[0%] Has a total of 5 questions
3:text

Text Files

We put our code into one or several text-files. This is the most simple type of file a computer system can work with, and they are very different from document-files, image-files etc. You do not need any advanced software to work with text-files, unlike document-files which require a word-processor.

Note: While text-based programming languages are certainly the most commonnly used, some are categorized as visual instead. You need special software to work with visual languages. They may be easier for beginners but they're considered inefficient and even ineffective in many cases.

Note: They come in two flavours; Block and Graph. Block-based visual languages have a similar structure to the regular text-based ones but Graph-based visual languages are instead structured as graphs with nodes and edges connecting them. We will only consider text-based programming languages in this course.

A document-file does not only contain the text you're writing, it also contains information about color, size, font, etc. They can even have images embedded inside of them. All of this is automatically managed for you by the word-processor.

A text-file contains nothing but the text itself. Because the computer will follow our instructions exactly, we need to be able to work with our code exactly. Having additional code being handled automatically behind the scenes would only make programming more difficult.

In code, even a single character can make a big difference so we need to see them all clearly. That's why we use what's called a monospaced font. That means every single character takes up the same amount of space. These fonts also render certain characters more distinctively so that otherwise similar characters, like the letter O and the number 0, aren't confused.

4:quiz
[0%] Has a total of 5 questions
5:text

Syntax Highlighting

It can still be hard to quickly scan programming code in order to find the exact piece you're looking for. Syntax highlighting is a feature built-into most of the text editors we use to write code. It colors special words and other characters differently so that we can more easily differentiate between them.

With syntax highlighting we can quickly understand and navigate the structure of some piece of code. The most important commands that make up the code jump out clearly and we get different colors for different kinds of things which reduces our mental load.

An other benefit is that it enhances the way a some code looks based on how it works, or what it does. It allows us to recognize different pieces of code much like, in a city, you might recognize different architecture styles or types of neighbourhods.

It is, however, important to note that the colors themselves don't actually mean anything. They are not part of the code, they're applied automatically by the text editor only while you're viewing it and are not saved in any way. Opening the same code in a different editor will show different colors, and they can even be changed in the same editor.

The rules for applying the colors are based on the rules of the language we're working with. Because of that we can often quickly discover the code-equivalent of spelling-mistakes because the editor failes to put the correct colors on the code we're writing.

6:quiz
[0%] Has a total of 4 questions