[Tutor] program-code dilemma

Alan Gauld alan.gauld at freenet.co.uk
Wed Jul 5 15:41:53 CEST 2006


> Lately I've been researching about the general definitions of 
> program
> and code, and I've realized that the difference is not so convincent
> (without mentioning simple and precise); that's why I'm sending 
> this.

It is very confusing especially for beginners, partly because both
words have multiple meanings dependant on context.

Thus:

>   Program.-  A sequence of instructions that can be executed by the 
> computer.

Is one definition. But program can have a wider application too,
as used by computer users. For example my "Word Processing
program" is actually a whole group of executable files and libraries.
All of which can be viewed as a program.

program is sometimes used to mean the end product of a programming
task, thus a DLL or other library once compiled into fina;l form might 
be
called a program.

>   Code.- Just the instructions of the program.

Usually code refers to the "source code", ie the program text
produced by a programmer or tool.

Code can also refer to "Object code" which is the preliminary output
from a compiler. This will be a binary format but one which is not
yet executable  - a link stage is needed for that to add in some
stanbdard header information and pointers to the standard libraries
used by the code - all of this extra stuff is used by the operating
system to create a running process.

And we can also get "Byte code" which is a kind of hybrid between
true object code and interpreted script. Python and Java use this
technique. The byte code for python is the compiled form found
in .pyc files.

And in a pure interpreted environment the difference between a program
and code is very hard to define since the interpreter executes the
code directly.

> Nevertheless for the few experience that I have, I know that a
> program also have comments; wich at the same time could be what
> differences a program from a code:

The comments are generally included in the definition of source code.
The compiler will remove comments so that they do not appear in the
object code (there are some exceptions to this). Comments are 
intrinsic
to an interpreted program so they a[popear inboth the code and the
program (it actually taleds the interprteter a small amount of effort
to throw away a comment. This is why modern interpreters
(Ruby, Python, Perl etc) usually compile the code into byte
code before executing it.

> The problem is that it seems too complicated for a definition so
> important and essential to start learning to program

Unfortunately computing has grown out of many different sciences
and engineering disciplines. Different terms arec used for the same
concept and the same term used for multiple concepts. It is a great
irony that a science which requires such preciusion of expression
as programming has not got a precisely defined set of terms to
describe itself!

> Although, I have clear that a program is like a container, and the
> code is like the internal structure that conform it. I think that a
> good analogy would be: "a code is to a program, what a GUI design is
> to a graphic application."

That depends on the GUI and the application environment.
Most GUIs are a combination of source code and graphical images,
its just that they use tools to generate it.

A better analogy might be that the source code is like the
sheet music that a musician processes to produce a tune.

This confusion of terminology is one of the reasons I spend a lot of
time in my tutorial attempting to clarify exactly what these different
terms mean in their various contexts.

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list