2. The Rules of Programming Languages

2.1. Introduction to the Syntax of a Programming Language

Every programming language has a set of rules:

These are rules, not guidelines or suggestions. They are the syntax of the programming language.

Image

Fig 2.1.1: The Syntax of a programming language

Now you can disagree with the rules if you like. You can privately think, some of them are stupid, but if you want to write a program that works, there are always rules you must follow. Many of the rules are very similar across multiple languages. So, with just a few basic questions, we can start to narrow down the characteristics, the things that make one programming language different from or even similar to another.

In the next section, we'll begin by covering 5 things we can ask about any programming language. First, we'll talk about case sensitivity.

Case Sensitivity

This will take care of one of a few questions you may already have about what it might mean when a source code you've seen is in uppercase or lowercase or mixed.

Statements

We'll then see common ways to write our instructions or statements in a programming language and particularly how you must end each instruction.

Whitespace

Whitespace is next. You’ll know why all those blank lines, indentation and spaces you see in source code are important, and who they are important to.

Comments

You’ll know why you should add your own notes in the middle of your source code.

Keywords

We'll talk about keywords, that is, those words that have a special fixed meaning within each programming language. It won't surprise you that different languages have different keywords, but there are also quite a few keywords you're likely to find in every single programming language.

Now these five things aren't the only aspects of a language I could talk about. I could also ask whether a language is usually compiled or usually interpreted as we covered in the previous chapter, but whether a language is compiled or interpreted is not obvious just from looking at it.

So, we will focus on what we can realize, what we can start to understand just from looking at it, and beginning to read the source code of a few different languages.