Test for Understanding of Programmability

From TimPenner.ca
Jump to: navigation, search

If you really understand the following little story, then you really do understand the essence of programmability. If you don't understand the story, then you probably don't. And if you're not sure, you probably don't. The story avoids basic terminology problems by providing explanations of key concepts. Don't rush. There is no scoring; you just have to know this for yourself.

How I acquired a compiler for my little computer

Background

Computer programmers write down instructions for computers to follow - that is, write computer programs - using words and phrases that humans can understand when they look at them. These words and phrases are composed according to the rules of what we call programming languages. Many such languages are designed to be useful in most any circumstance; others are designed to suit very special purposes. Programmers speak of writing programs in various languages. "I wrote a game in Java". Or, "I wrote a date converter in Perl." The text that programmers write down according to the rules (syntax) of programming languages is often called source code, because it is the source of instructions encoded in a language.

One very general language with which I am familiar is named C, after the third letter of the alphabet. Not a very inspired name, truly.

Programmers then use one of two different methods to get the computer to understand and follow the instructions in the programs they write. Not that they often have much choice about which method to use. That decision is made by the people (other programmers) who set up the programming system that's being used. How that comes about isn't important to this story.

Note to experienced programmers
Please excuse the simplifications used here. I really do know that systems such as Java store intermediate versions that need a run-time environment, so the idea of interpretation hasn't been perfectly clear since the days of UCSD Pascal. Even Perl does this although I'm pretty sure Bash doesn't. And I have also glossed over the necessities and use of object code, generated by compilers, that needs linking, as pragmatisms of operating environments.
Method 1 - Interpreter
An interpreter is a computer program - a software tool - that scans the text of a computer program - the source code - and follows the instructions it encounters. So, for example, if the computer program says to send a message, a piece of software is invoked to do just that. Interpreters contain all the software they need to do whatever a computer program might need to do any job that the language is capable of. When programmers use interpreters, they think in terms of running their programs in (or with) interpreters. Of course, each interpreter is designed to interpret a given language.
Method 2 - Compiler
A compiler is a computer program that, like an interpreter, scans source code, but the similarity stops there. What it does is convert the instructions into a form that is essentially raw instructions for the electronics of the computer's central processing unit (CPU) to act on. That converted (compiled) version is stored permanently to be fed into the computer - that is, run - sometime later. Compiling is the act of using a compiler, as well as what a compiler is said to be doing when it is doing its job. Programmers also speak of running a program through a compiler. Of course, each compiler is designed to compile a given language.

Here's what happened

I wanted to be able write programs in C on a little computer I had many years ago. I found a C interpreter that did an OK job, but it used a lot of memory while it was doing its job of running C programs that I had written. It contained all the instructions it needed to do all kinds of things that I wouldn't ever need, as well as the things I did need. I would have rather used a compiler that would create and save tiny compiled versions of my programs consisting of the few instructions I wanted the computer to follow. But I couldn't find a compiler that would work with my computer, just the interpreter.

Then I found the source code of a C compiler, written in C. Of course, a compiler is just a computer program and C is a general purpose programming language, so this makes sense - a C compiler written in C - right?

So I ran the C compiler through itself, the C compiler, by running it in the C interpreter. In other words, I used the interpreter to run the compiler to compile a copy of itself.

The result was a compiled version of a C compiler I could use, without all the baggage of the C interpreter, to compile my own programs from then on.

Did you get that?

A byproduct of understanding this is to realize how the history of computer language development has occurred - hoisting computer languages by writing compilers in the very languages they compile. I'm prepared to answer questions. Please use my contact page.

Category:Explanation


Personal tools
Namespaces

Variants
Actions
Navigation
Contact
Areas Intros
References
Tools