Program Arcade GamesWith Python And Pygame
What makes a computer language? Why do computers have them? Why are there so many different computer languages?
Like understanding how an engine works isn't necessary to drive a car, it isn't necessary to understand the answer to these questions to do basic programming. However to progress to an advanced level, it is necessary to understand how a computer works. This provides a brief explanation to get started with.
Computers are electronic, and they are digital. To a computer everything is in terms of no voltage potiential 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.
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, or first generation programming language.
Binary numbers are usually represented in groups of four. For example:
1010 0010 0011
An improvement over entering programs via switches was the use of hexidecimal codes. The decimal numbers used by most people use the digits 0-9. Hexidecimal uses the numbers 0-9 and A-F to represent a set of four switches, or the numbers 0-15.
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. This type of language is called a 2GL language, or second generation 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.
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.
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.
There are many different computer languages today. Because computers perform so many different types of tasks, different languages have been developed that specialize in different tasks. Languages such as C are good for operating systems and small embedded computers. Other languages like PHP specialize in creating web pages. Python is a general purpose language that specializes in being easy-to-use.
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 orgins 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.
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.
Click here for a multiple-choice review quiz.
- Give an example of a binary number. (While a number such as “1” can be a binary, decimal, and hexidecimal number, try coming up with an example that better illustrates the differences between the different bases of numbers.)
- Give an example of a decimal number.
- Give an example of a hexidecimal number.
- Convert the numbers 1, 10, 100, 1000, and 10000 from binary to decimal.
- What is a compiler?
- What is source code?
- What is machine language?
- What is a first generation language?
- What is a second generation language?
- What is a third generation language?
- What is an interpreter?
You are not logged in. Log in here and track your progress.