Dynamic Common Lang
You don't have to install Common Lang on your computer. As a purely educationally-driven language, it runs directly on this site. For now you will see widgets embedded in the text itself while the basics are introduced. Later, a full development environment will be used.
The goal of this guide is clarity and deep understanding of underlying concepts. There will be vanishingly few times throughout this guide when you will be asked to "not worry about the details of this code". Magic is a term for things that aren't understood and so one should always worry about things that feel magical. However, in order to kick things off, we will ironically have to start with such a worrying moment:Lines 1 and 3 are magic. In other words, they serve a necessary purpose and will be fully explained later. Feel free to worry about them a little bit but don't let that prevent you from looking at line 2.
If you push the "run" button, you can see the message Hello, World! appear in the output panel.
In general, each line of code is a specific instruction and each line runs sequentially.
Since there's only one line (aside from lines 1 and 3), our code only did that one thing. That thing was to print out the phrase "Hello, World!" to the output panel.
While it may seem vaguely sensible that this is what the line does, it's a good opportunity to break this line apart and discuss specific vocabulary that we can use to introduce more complicated code.
The Semicolon
As a general rule of thumb, each line ends with a semicolon (;). This tells the compiler that it's the end of the line. The reason why this is necessary is that, like most programming languages, Common Lang ignores spaces and line breaks. There needs to be an explicit declaration that the line is over. As code gets more complicated, you may want to wrap the line across multiple lines. The semicolon allows us to do this without introducing ambiguity.Note that spaces, line breaks, and tabs are collectively referred to as whitespace.
Strings
The "Hello, World!" is a piece of literal text. If you recall from a previous section, we gave text a specific term: "strings". This is a string.To use a string value in your code, the text is surrounded by quotation marks "like this".
A printer? Surely not.
Finally, we come to print. This command has nothing to do with printing documents. This tells Common Lang to display the thing in parentheses on the output panel. Most programming languages have some notion of an "output panel". In this case, it's a literal panel next to the code. This allows us to display information from our code. In this case, we want to show the string.Many of the commands will follow this same pattern. There will be a name of the command, followed by parentheses. Inside the parentheses will be the information needed for the command to run.
Printing a string feels redundant. We can plainly see the string in our code and so it feels like there is no value gained by displaying it again a few centimeters away. The true power of print will be evident when we start generating new data.
Combining Expressions
In addition to strings, one of the fundamental data types was numbers.There are actually two types of numbers: integers and floating point decimals (or floats for short).
Integers are whole numbers.
Floats are decimals, and we're going to ignore them for now.
Instead of printing a string, we could print a number:
This does basically the same thing as the previous example. Let's make it interesting:
This time instead of seeing 4 + 17 appear in the output, we see 21.
While this might seem obvious to carry-the-1 enthusiasts, there's still a bit of vocabulary to learn here.
4 + 17 is something called an expression. An expression is any piece of code that will resolve into a specific value. In this case, we expect this expression to resolve into a number because we're adding two numbers together.
In fact, we can also say that 4 and 17 themselves are expressions because they are pieces of code that resolve into a value. Their values are obvious because they are integers themselves, but technically speaking, they are expressions.
The + symbol represents addition. However, more generally, we call this an operator. There are many kinds of operators such as subtraction (-), multiplication (*), and division (/). An operator is code that combines expressions together (usually two of them) to form a new expression. Most operators are a single symbol and work from left to right.
If you are logged in, you can add these terms to your study list and use the flashcards app. Otherwise, you will have to settle for this table.
expression | A piece of code that, when run, will resolve into a single value. |
operator | A piece of code (usually a single symbol) that represents an action that will join multiple expressions together to create a new expression. Such as addition (+). |
value | A single piece of data. Such as an integer or a string. |
integer | A number. Specifically a number that is a whole number, not a decimal. |
float | A number. Specifically numbers with decimals. "Float" is short for "floating point decimal". |
whitespace | A general term for blank and formatting characters in text, such as spaces, line breaks, and tabs. Most whitespace is usually ignored by most programming languages. |
semicolon | The ; character, which unambiguously indicates the intended end of a line. The intended end of a line cannot be indicated by an actual line break since the Common Lang compiler ignores whitespace so that you can wrap lines for clarity. |
magic | A term for anything you don't understand yet. |
A command that causes a value to appear in a programming language's output panel. While the definition of "output panel" changes depending on the programming language, the term "print" is fairly universal. |