Challenge 7-1: Introduction to Compilers

Challenge 7-1: Introduction to Compilers

Compilers

Compilers are a very important part of programming. They translate programs into the language needed for the computer to be able to run it.

A common compiler will be able to translate from a high-level language, like Python or C++, into a low-level language such as machine / assembly / object code.

Compilers are also very useful for checking a program before you finish and build it. During building it will perform error checks to find issues with the program like the syntax used. This is very useful because building can take a long time so the last thing you want is for the build to finish and then realise you forgot a bracket.

But what does translation mean? We haven't been writing our programs in French - sure, Python is a language, but we write it in English, so what translation needs to happen?

When writing programs, the programmer will normally use a high-level language such as Python. High-level here means that the language is quite separated from the actual hardware of the computer. We might use Python to tell a computer to print "Hello" to the screen, but we don't really need to know anything about the screen and how it works to get this program to run. Low-level languages on the other hand, like COBOL (which Grace Hopper helped to invent!) tell the computer exactly what to do down to the very last detail. This would be exhausting to write by hand, but it can be really useful if we want to exactly define the computer's behaviour.

Basically, high-level languages let us describe what we want the computer to do. Low-level languages let us describe how we want the computer to do it.

High-level languages are great for us as humans because we can read and interpret these languages much more easily than machine code, which is a vast amount of binary. The trouble is that the computer has the opposite problem; it knows how to read binary, but Python makes no sense, therefore we need a translator.

Imagine your program is an instruction manual of how to put together a new media stand with all the bells and whistles, and the computer is you. Your instructions are useful, but they're in a language you don’t understand, so now you don’t know where to start. Imagine now your friend walks in and they happen to know that language and offer to help. They go away and come back with a brand-new instruction manual that is written in English! Finally!! Now you know exactly what to do and you can get to building your media stand.

As you can see, your friend is very important in making sure that you can get the job done. In terms of programming, your friend would be the compiler.