Chapter 2: What is a Computer Language?
What makes a computer language? Why do computers have them? Why are there so many different computer languages?
It isn't necessary to understand the answer to these questions to do basic programming, just like understanding how an engine works isn't necessary to drive a car. However to progress to an advanced level it is. This chapter provides a brief explanation to get started with.
2.1 Short History of Programming
Computers are electronic, and they are digital. To a computer everything is in terms of no voltage potential along a wire, or some voltage available. No voltage means a zero to the computer, and some voltage means a one. Computers can't actually count higher than that without combining multiple ones and zeros.
In the early days, switches were used to load ones or zeros into computer memory. Figure 2.1, courtesy of Wikimedia Commons, shows an Altair 8800. The front panel switches were used to load in the program. The lights showed the output. There was no monitor.
Figure 2.1: Altair 8800
Each set of on/off switches represented a number. Each number would represent data or an instruction for the computer to perform. This system of only using ones and zeros to represent numbers is called the binary number system. This type of computer language is called a 1GL (First Generation Language). Note: There isn't a language called 1GL, it is just an abbreviation for First Generation Language. 1GL is the same thing as the machine's native language (machine language) where numbers represent the commands and data for the program.
Binary numbers are usually represented in groups of four. For example:
Both data and computer instructions are stored in binary. Machine language are the binary numbers representing instructions that the computer interprets. Not all binary data is machine language however. Data such as documents, databases, financial figures are also stored in binary on the computer. This data is, of course, not intended to be run by the computer.
An improvement over entering programs via switches was the use of hexadecimal codes. The decimal numbers used by most people use the digits 0-9. Hexadecimal uses the numbers 0-9 and A-F to represent a set of four switches, or the numbers 0-15. See the table below for an idea of how binary, decimal, and hexadecimal relate.
Binary Decimal Hexadecimal
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F
1 0000 16 10
Video: Decimal, binary, and hexadecimal systems
In order to make entering programs easier, later computers allowed users to enter programs using assembly language. Each command used a mnemonic, and a program called a compiler would change the mnemonics into the numbers that represented the commands. Assembly Language is also called a 2GL language, or Second Generation Language.
Figure 2.2 shows part of an example assembly language program, also courtesy of the Wikimedia Commons.
Figure 2.2: Example assembly language
While this was an improvement, it still wasn't very easy to program. The next generation of languages allowed for higher-level abstractions. The first of the third generation languages (COBOL, FORTRAN and LISP) were a lot easier to understand and program.
The second and third generation languages used a program called a compiler. A compiler takes the program typed in by the user (called source code) and turns it into machine code. The programmer then runs the machine code. The original source code is not run.
If there are several pieces of source code in a program, they can be linked together into one program with the use of a program called a linker. The linker is run on the machine code generated by the compiler to generate a final program. This final program is what the user runs, and the original source code is not needed.
Figure 2.3: Compilers and linkers
A disadvantage of compiling to machine language is that the program only works for that particular type of machine. Programs compiled for Windows computers do not work on Apple Macintosh computers, or Linux computers.
Because the whole compile and link steps could be complex for new programmers, some languages instead ran using interpreters. These programs look at the source code and interpret it to machine language instructions on the fly. It also allows the same programs to run on Windows, Mac, and Unix computers, provided there is an interpreter available for each platform.
The drawback of using interpreters is that it is slower to operate through an interpreter than in the machine's native language.
Figure 2.4: Interpreter
Python is an example of an interpreted language. It is easier to develop in Python than C, but Python runs slower and must have a Python interpreter to work.
Languages such as Java use a system where programs are compiled to machine code that runs on a Java Virtual Machine (JVM), rather than the actual machine. Another popular language that does this is C#, a Common Language Infrastructure (CLI) language that runs on the Virtual Execution System (VES) virtual machine. A full discussion of these is beyond the scope of this book, but feel free to read up on them.
The company Tiobe keeps track of the popularity of various programming language in their index that is updated each month. It is a good idea to look here, and at job placement boards like DICE to keep up to date with what languages employers are looking for.
Thankfully almost all languages share the same common elements, and once one language has been learned, the same theories will apply to the other languages.
For an entertaining history of computing, I recommend watching: Triumph of the Nerds by Robert X Cringley, a three part series on the origins of computing. The movies are entertaining enough that your entire family might enjoy them. I also recommend the book Accidental Empires if you are more into reading than video.
Triumph of the Nerds Part 1
What happens after those videos? They don't even cover the birth of the Internet! Then check out the video series Nerds 2.0.1 also by Robert X Cringely.