-*- Text -*-
   This is the file .../MOOSE/info/Progrmng.nfo, which contains info
about Programming and the MOOSE.


File: Progrmng.nfo		Node: Top	Up:(MOOSE.nfo)

* Menu:

About this document:
* Foreword::			What is this document and how to use it.

About Programming:
* Intro::			What is Programming ?
* Human versus Machine::	Two opposite issues.
* The Language::		The intermediate between the two.
* Programming levels::		different levels of Programming.

Very Low Level Programming paradigms:
* Words::			Elementary information.
* Memory::			How the computer organizes information.
* Code::			Effective orders the computer understands.
* I/O Control::			How a program accesses the external world.

Low Level Programming paradigms:
* Stacks::			A basic computing paradigm.
* Continuations::		What to do next.
* Calling conventions::		Agreeing in one way among others to do things.
* Memory organization::		How the memory is divided.
* Optimization::		Having something done in the best way.

Medium Level Programming paradigms:
* Recursivity::			What is Functional Programming.
* Distributivity::		What is Distributed Programming.
* Objects::			What is Object-Oriented Programming.
* Events::			What is Event-Programming.

High Level Programming paradigms:
* Genericity::			Saving time and effort.
* Constraints::			Expressing relations between objects.
* Proofs::			Prooving that programs verify constraints.
* Solving::			

Limits of programming:
* Size::			The limits of computer memory.
* Speed::			Speed limits for calculations.
* Human skill::			The Ultimate Limit in computer programming.
* Human cost::			After all perhaps THIS is even more ultimate !

Appendix:
* Common programming languages::

File: Progrmng.nfo, Node: Foreword, Next: Intro, Prev: Top, Up: Top

   This document does NOT try to teach anybody how to program anything
in particular; look for a tutorial or a programming primer for that. It
tries to explain WHAT are programming and the major ideas behind programming.

   One should read this document to help him understand what he or others
do when programming, thus enhancing his skills or enlightening him about
what he could have regarded be magic (nothing should be regarded as being
magic by a cultured sensible man). He may read and reread it before, while,
or after ever learning how to program.

   Note that a choice had to be done while writing this document, whether to
s from the highest to the lowest or from the lowest to the highest level of
programming abstraction. The choice was finally a systematic down-top approach,
from the lowest level to the highest one. People knowing too well low level
programming may want to skip the first nodes, or read it the text in the
reverse order. If you have any occasion, please tell me what order you think
is the most useful for a first reading.

   The author suggests that the reader be aware of the restrictions imposed by
the nature of computers (see Low-level programming paradigms), and a little
bit of theory of information or elementary combinatorials to understand it
before he reads this document (i.e. know how to write a number in basis 2 or
n, know what quantity of information contains some amount of data, and what
size of data is required to hold such quantity of information).

   Have a Happy Hacking !

File: Progrmng.nfo, Node: Intro, Next: Human versus Machine, Prev: Foreword,	Up: Top

   MOOSE has admittedly been designed by so-called ``programmers'' for
so-called ``programmers'' to use. But what is programming ? This is what this
topic is about.

   Programming is telling the computer (or anything that will obey) what you
want it to do. The mere fact of giving the computer any order may be considered
programming. Of course, if the computer is to face a complicated environment,
a huge number of cases must be taken into account so that one can be sure of
the machine's behavior; that's why we can't (at this time at least) program a
machine to simulate human understanding. Its potential complexity (which can be
justified by mathematical arguments) makes an art out of Programming.

   This does NOT mean programming should be reserved to professional
programmers. In the same way as anyone can enjoy music, dance, poetry,
cooking, mathematics by hearing, seeing, reading, tasting or grasping it, one
can appreciate a good program merely by using it, and needn't be able to
perform as well to do so. In the same way as anyone can sing a tune, dance a
folk-dance, declaim a poem, cook a little dish or do elementary mathematics,
one can write a small program.

File: Progrmng.nfo, Node: Human versus Machine, Prev: Intro,			Next: The Language, Up: Top

   There are two opposite sources of problems in programming.

   The first source is Human Understanding of the program: what exact behavior
should one expect from the program, how the program may be divided in more
easily understandable components, and how these components should be related,
of what more general program are these components a specialization and in what
way, etc. Human understanding in general may be developped in many other arts
and sciences; I recommend that one should never stay a stranger to any of them.

   The second source is Computer Understanding of the program: how human and
machine representations correspond (Programmers say how a human abstraction is
implemented, and too rarely how machine data should be printed), by what
effective computations can a relation be enforced. Machines are far less known
by the public, yet are much simpler. The reader should know that the machine is
basically designed only to execute very elementary orders (see Very Low Level
Programming paradigms, * Words::, * Memory::, * Code::, * I/O Control::). I
suggest that any programmer (thus potentially any human) have at least a little
idea about how a machine works and why (i.e. machine language and electronic
circuitry).

   All the Art of Programming will thus consist in reconciliating those two
points of view: The human will have to achieve understanding firstly of what
he wants to program, and secondly how the computer can learn it, then he will
have to express that correctly to the computer. I think the last part flows
naturally from the first two; doesn't a french proverb says
	``ce qui se pense bien s'enonce clairement
	  et les mots pour le dire viennent aisement.'',
which means
	``what is well conceived can be clearly told,
	  and words to tell it come easily.''. ?

   To explain anything to a computer, the Programmer must use one of many
specifically designed languages. The work of the (currently humans) language
designers is to make the last task easy enough so that the Programmer can
focus on the later task as short and simple as possible, so that the
programmer can focus on the first two points: understanding. Moreover, they
must help the computer understand as much of the work as possible by itself,
so that the Programmer may more precisely focus on non-trivial issues.
However, there is at this time very much to do in this field, and that's what
the MOOSE project is all about.

File: Progrmng.nfo, Node: The Language, Prev: Human versus Machine,		Next: Programming Levels, Up: Top

   For the human programmer and the machine to communicate (and even for
machines to communicate one with the other, or for the same machine to talk
to itself), a Language is needed. The media for this language can be speech,
movements and clicks of a mouse, or more commonly a list of symbols (including
the roman alphabet) which both humans and machines are known to manipulate
relatively easily. A language is then a particular subset of the the set of all
combinations of such events or symbols; and for the computer to understand it,
this subset must be easy to describe and understand.

  The programmer must learn to speak the language by studying it through theory
and practice. So must the machine: a particular program, called a compiler or
an interpreter, serves as an intermediate between the language and the machine.
If the intermediate program executes the given orders as it reads them,
it is called an interpreter; if it'd rather write some code that the machine
can later execute, it is called a compiler (a compiler more generally
translates a program from one language to another, which can be in turn
executed directly by the machine, interpreted, or subject to further
compilations).

   An interpreter generally allows a quicker interaction between the man and
the machine for orders are executed at once, whereas a compiler can generally
produce a code that executes faster, as it may take into account the whole
program and not only the past and present orders. However, compiling for
increased speed is so slow that its interest is only for finished work or
computations whose time is longer than the compilation time. Languages have
a compiler or an interpreter (or both) according to their own history, and to
the fact that a statement in the language may or not rely on other future
statements in its own future. Compilers also have reached suppremacy in
the times when computers didn't offer enough interactivity for their advantage
to appear, and compiled-only language have remained the most used since.

   Current technologies may allow an interpreter/compiler combination that
would take the advantages of both worlds. But the inertia of public software
made it impossible to realize.

File: Progrmng.nfo, Node: Programming Levels, Prev: The Language,		Next: Words, Up: Top

   Programmers usually distinguish levels of abstraction (they simply say
levels) in the Art of Programming. A Language is said to be concrete and to
have a low level of abstraction if and only if (iff) it solves easily problems
arising from Machine Understanding. Conversely, a language is said to be of a
high level of abstraction iff it solves easily problems arising from Human
Understanding (which is more difficult to define).

   At the lowest level of abstraction is the machine language, that is, code
directly readable and executable by the machine (which depends on the kind of
machine used). For humans to program at the lowest level, there are assemblers
that translate rather straightforwardly a list of textual "opcodes" into
machine language; to ease repetitive tasks, macro-assemblers offer, in addition
to assembling, powerful compiling directives and the possibility to define
macros (a short name for macro-instructions) that are enhancements of the
language.

   At a still low level, but generally sufficiently high to allow porting
from one machine to another (that is using the same programs one more than one
kind of machines) are imperative languages, languages that consist in giving
orders or giving names to lists of orders. These languages are all the more
abstract that they do not depend on the actual machine representation of
orders, that they introduce concepts that mask actual implementation (such
as structured data and programming).
   See plain FORTH or at the opposite (but all low-level languages) C and
mid-80's Pascals. These language enforce each their own implementation of
introduced abstractions; programming them IS implementing. Changing the
actual organization of data implies modifying the whole thing.
   Some low-level languages, like older BASICs and Pascals, lose their grip
on the machine representation, and thus, have no interest as low-level
implementing languages without having the advantages of higher-level languages.

   At Medium Level, we have imperative languages that include strong typing,
functional or object-oriented concepts to separate implementation from
specification. The language includes type checking as a sanity bounds and a
way to put a frontier between specification and implementation; the more the
type-checking is independant from implementation, the higher-level the
language. Lisp and its successor Scheme, Object Pascals and C++ , Modula-n
and Ada, Smalltalk, are such Mid-Level languages that allow (or enforce)
an increasing abstraction of the specification from the implementation. But
still, these languages have no way to tell why an object implements well such
external problem, and not another of the same type.
functions for ML or objects for Smalltalk, orca, that are the lowest-level
Mathematicians may view Mid-Level as the dual of Low-level: we take interest
in the type of objects, that is the action that these objects have on others.

   High-Level programming languages solve relationships between objects:
have a truely unifying concept. For example, the ML functional language has
functions as the unifying mathematical concept; even if still near from
imperative languages, ML is abstract enough so that ML programs are their
own specifications; but you can specify only solved problems (as a
specification is here its own solution). Prolog solves relations, but
lacks functional relations
Those languages unhappily don't allow to associate efficient implementation
to the generic problems exposed. New programming languages under
development appear that embody constraint programming together with proof of
implementation's correctness.(but the industry's inertia and competition, lack
of cooperation, and the bad quality of lower-level tools still forbid one, See
Coq, B, ...

   Higher-Level programming languages aren't very known to the public; they
are experts in math, physics, medecine, economy. They're seldom well tuned,
and still have many bugs; because few people use them, and lower languages
currently are bad tools.

   What MOOSE proposes is an integrated environment that encompasses all
programming levels. A self-extending imperative language OSL serves as a
macro language, a machine language generator, as well as a target language
for the medium level language that is only syntactic sugar and testing above
OSL for its lowest part. The medium level language itself (more exactly some
isomorphic machine representation of its higher part) serves as a target for
the solver of the high-level constraint language.

File: Progrmng.nfo, Node: Words, Next: Memory, Prev: Programming Levels,	Up: Top

   Computers are electronic circuits to manage information. The unit of
information is the bit, or binary digit; it can take one of two states,
named 0 and 1. Computers group bits by eight, forming bytes, and by larger
clusters named words (each typically 16, 20 or 32 bit long, according to
the computer architecture). With some number n of bits, you can code
2 exponent n different combination (1 combination for no bit, doubles each
time you add one bit to the cluster).

   Thus, with 4 bits, you can the 16 combinations 0000,0001,0010,0011,0100,
0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111, thereafter named
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F, that form the hexadecimal digits (digits
in basis sixteen). With 6 bits, you can code 64 different combinations, which
isn't enough to cover the 26 roman letters in both uppercase and lowercase
together with 10 ciffers and some tenth of punctation marks. However, the 128
combinations offered by 7 bits suffice to code all comon symbols to write
english, together with some extra "control characters" (see ASCII code).

   With one byte, you have 256 different combinations. With a 10 bits, you
can code 1024 combinations, which you call a kilo or K because it's just a
little more than 1000 ; thus 1 K or 1 Kbit is 1024 bits ; 1 KB is 1024 bytes.
similarly, 20 bits code 1,048,576 possibilities, which we call a mega-,
because it's near 1,000,000, and 30 bits code over 1,037,000,000 possibilities,
which we call a Giga- (more than a billion) ; 40 bits similarly are a Tera-.
So we have mega-bits (1 Mbit= 128 KB) or mega-bytes (1 MB=8 Mb), Giga-bits,
giga-bytes and so-on.

File: Progrmng.nfo, Node: Memory, Prev: Words, Next: Code, Up: Top

   These years (around 1993), a personal computer can use words one at a time
at a rate of tens of million words each second. It can read and modify a set
or word cells called the memory; each cell is determined by a unique number
called its address and typically also a word.

   In current computers, addresses often correspond to byte cells, and byte
cells with consecutive addresses are grouped to form a word cell. Thus, a
computer with 32-bit long words (more shortly called 32-bit computers) can
give 4 G different addresses and address directly up to 4 GB, that is 1
Giga-Word (because the computer needs 4 bytes to form one word). Today's
personal computers' memory typically is a few megabytes, so there is no
addressing problem.

   To store large amount of data, and because a computer's main memory is often
volatile (i.e. it clears when the computer is turned off), computers use
magnetic or optical tapes and disks, that can contain mega- to giga- bytes
each. It is much slower, but it can contain more securely far larger amounts of
data for a longer time, and thus is call mass storage (or mass memory). You can
also exchange data from one computer to another using some magnetic/optical
disks (or magnetic tapes) as a media.


File: Progrmng.nfo, Node: Code, Prev: Words, Next: I/O Control, Up: Top

   A computer executes very elementary orders stored in the main memory.
At every cycle, it fetches a word (or a sequence of bytes of variable length)
from memory and executes a very simple instruction coded by this word; at the
next cycle, it will fetch its instruction from the word with the next address.
Instructions will typically consist in adding or substracting two words,
comparing two words, moving words from a cell to another. Special instructions
change the address of the next instruction to fetch (often called program
counter or instruction pointer) according to the previous comparison.

   To have smaller instructions, and because fetching from memory may appear
too slow to some computers, microprocessors (the chip in the computer that
interprets instructions) have internal cells called registers. The program
counter is one of these register, but a microprocessor always has other
registers, for the arithmetics, for addressing memory, etc.

(Note: when a computer is turned on, it always begins to execute instructions
at the same address, where the computer factory installed some kind of memory
that can't be erased or written. A small program there will typically load
memory with a program from mass memory, then execute it, so you can choose and
change the program it will execute).

(!!! To be done !!!) ...


File: Progrmng.nfo, Node: I/O Control, Prev: Code, Next: Stacks, Up: Top

   To access the external world (and not only its main memory), the computer
has special instructions that activate special builtin cuircuitry.
File: Progrmng.nfo, Node: Genericity, Next: Objects, Prev: Stack primitives,	Up: Top

   Genericity is describing not a particular object, but a whole class of
similar objects, that you can particularize in any way, or manipulate as such.
Thus, when you code something, you musn't rewrite it each time you change a
detail, or write inefficient code.

File: Progrmng.nfo, Node: Objects, Next: , Prev: , Up: Top


File: Progrmng.nfo, Node: Common Programming Languages, Next: Top,		Prev: Human Cost, Up: Top


File: Progrmng.nfo, Next: Node: Common Programming Languages, Next: Top,		Prev: Human Cost, Up: Top

Level:					Notes:
-----					-----
Very Low	binary			For machine use only.
		assembler		For kernel hacking only.
Low		macro-assembler		Good for critical code, but unportable.
		FORTH			quick and small, not yet portable.
		C			Horrible, but a standard.
Medium		Pascal			Clean, but unpowerful.
		Objective Turbo-Pascal	Clean, but not a standard.
		C++			horrid, but the new standard.
		Lisp			Too dirty.
		Scheme			A Cleaned lisp.
High		ML			Very clean, but no access to low-level.
Very-High	Coq			produces ML. Being improved.
All-Level	OSL			Only a draft.

