2. Our programming language
English works with certain rules, and so do programming languages. It will not matter which one you’re talking about, as they are all similar. Since this work will not be affiliated with any specific one, we’ll deal with a hypothetical computer language, which we’ll call P language. It will have very specific rules, which we shall introduce from time to time. Learning it should give you a good grasp of what any other computer language involves. Since computer systems encompass a vast area of knowledge, we shall only cover a small subset, namely programming.
Just as there are basic elements to English, P language has those same constituents. Our language will use the letters of the alphabet a through z and other special characters. We will not need capital letters but if ever someone uses one by mistake or otherwise, that will not be a problem. Our system will simply assume it’s the same letter as lower case. The letters of the alphabet will be used together to form words, just as in English. There will be three resulting uses of these words. The first will stand for a variable – which shall always be represented by an underlined word. Once we get into a program, you’ll see the underline used. A variable will represent a value for a field. We could use the field or variable
balance
to represent a bank balance for someone’s checking account or the variable
interest-rate
could be the rate the bank pays on this checking account. Note that both these fields will change in value and that’s why they’re called variables.
The next use for a word will be for something very significant in our computer programs. These represent concepts – we’ll get into them shortly – as well as verbs dictating specific action to be taken. Referred to as keywords, each will be in bold print. Thus
might be used to get a report printed on a piece of paper. Whenever it is used, it will always accomplish the same thing, that is, produce output for a report. For that reason, these words are defined to our system and cannot be used for ordinary variables. They are keywords or reserved words. Usually a system has a list of all these words. Our system will be no different and a list can be found at the back of the book. We will define and describe these verbs as we use them.
The third use will be for a label of a paragraph, which we’ll get to later. We’ll also use operators – usually a single character – to do a few things, such as addition or multiplication. To add the variable
deposit
to
balance
we could write
deposit plus balance
but instead we shall say
deposit + balance.
As you can see, our operator is the plus sign. There will be operators for subtraction and division as well as logical operators, which are used to make decisions in programs, when we need them. We will get into these later.
Hence, we have variables, keywords, labels and operators. Variables can use any letters of the alphabet, numbers as well as the hyphen. No other symbol will be allowed. Each variable must begin with a letter and cannot start with a hyphen or number. The following are all valid:
initial-balance
deposit
jxqrtk
x
x-1-y-2
Each of the following are invalid:
bank balance – it has a space or blank between the end of one word and the start of the other and that is not allowed
3rd withdrawal – the first position is a number, which is not allowed
x – 1 – the spaces around the hyphen are not acceptable
in&out – the & symbol is not allowed in variables
As far as the size of the field, there will be no limit; but some considerations are in order. If you use x for a variable, it will be valid, but it might be difficult to understand what it represents. If it is to stand for monthly maintenance fee, why not use monthly-fee? For a due date you could use z but due-date will be more appropriate. It will be more meaningful. Thus a rule to use will be to make the field name long enough to have significance but don’t forget you have to key it in, so don’t make it too long either.
As far as keywords and operators go, the former by their very makeup should be easy to figure out regarding what they do. Usually operators will be a single character. If there is any doubt as to the meaning of either of these, refer to the index at the back of the book for a list and descriptions of keywords and operators.
Putting together variables, keywords, labels and operators will result in a phrase or sentence, not unlike the English language. In our case though this will become a line of our program. Note that there will be rules to follow for each line and so far there has been a hint of some of these constraints. We shall get into more specifics later. Taking a group of valid lines of code and assuming some rules are followed, the result will be a section or paragraph of our program, just as we had for the English language. With more rules being met, a certain group of paragraphs or sections put together will result in a computer program, which parallels our chapter in English.
Finally putting a group of programs together with further considerations will result in a user application. This is very similar to our novel or work of non-fiction in English. We could proceed further by grouping a few applications together to give us a computer system. This we saw as our library in English. Our concern in this work is programming so we will concentrate on that aspect and only mention applications and systems on occasion. You can see that P language and all it encompasses is very similar to what is involved with English. There are many similarities.