[Tutor] programming definitions for a newbie.

Alan Gauld alan.gauld@blueyonder.co.uk
Wed Jun 18 16:22:22 2003


Hi Tristan,

> Is someone able to define (in as non-programming
> language as possible) the following terms in relation
> to what they actually in a very broad and basic sense.

Thats what I try to do with my tutorial. Especially in the
early chapters.

I'll cut n paste some examples into this mail, if you don't
understand the explanations please let me know so that I
can improve them for the benefit of future readers.

> *module-

---------

When you start Python there are a bunch of commands available
to you called built-ins, because they are built in to the Python
core. However Python can extend the list of commands available
by incorporating extension modules. - It's a bit like buying
a new tool in your favourite DIY shop and adding it to your
toolbox. The tool is the sys part and the import operation
puts it into the toolbox.

In fact what this command does is makes available a whole bunch
of new 'tools' in the shape of Python commands which are defined
in a file called 'sys.py'(*). This is how Python is extended to
do all sorts of clever things that are not built in to the
basic system. You can even create your own modules and import
and use them, just like the modules provided with Python
when you installed it.

(*)Actually 'sys' is a special case and 'sys.py' doesn't exist,
but most modules use that kind of naming scheme

--------------


> putting in "import cgi".  But how can i dump a raw
> object from cgi into an html page just to see what it
> looks like?  Or am i confused as to what the cgi
> module can do?

I think you are a little confused, you need to read the tutorial
on CGI from the Python web site maybe. To use the Python cgi
module does require some knowledge of how the CGI protocol
works. Its not IMHO as easy as the Perl CGI module, although
arguably its more flexible.


> *object orientated programming

Theres a whole section on this in the tutor but the definition
bit is here:

-----------------

Data and Function - together
Objects are collections of data and functions that operate on
that data. These are bound together so that you can pass an object
from one part of your program and they automatically get access to not
only the data attributes but the operations that are available too.

For example a string object would store the character string but also
provide methods to operate on that string - search, change case,
calculate length etc.

Objects use a message passing metaphor whereby one object passes a
message to another object and the receiving object responds by
executing one of its operations, a method. So a method is invoked on
receipt of the corresponding message by the owning object.

------------------

> *arrays

---------------
Array or Vector
A list of items which are indexed for easy and fast retrieval.
Usually you have to say up front how many items you want to store.
Lets say I have an array called A, then I can extract the 3rd
item in A by writing A[3]. Arrays are fundamental in BASIC, in
fact they are the only built in collection type. In Python
arrays are simulated using lists and in Tcl arrays are
implemented using dictionaries.

---------------
NOTE: indexing, lists, dictionaries and collection types are all
explained earlier in the same section.



> *classes

WE're back on OOP here, but specifically a class is described as:

---------------------

Defining Classes
Just as data has various types so objects can have different
types. These collections of objects with identical characteristics
are collectively known as a class. We can define classes and
create instances of them, which are the actual objects. We
can store references to these objects in variables in our programs.

Let's look at a concrete example to see if we can explain it
better. We will create a message class that contains a string
- the message text - and a method to print the message. ....



...What we have so far is the ability to define our own
types (classes) and create instances of these and assign
them to variables. We can then pass messages to these objects
which trigger the methods we have defined. But there's
one last element to this OO stuff, and in many ways it's
the most important aspect of all.

If we have two objects of different classes but which
support the same set of messages but with their own
corresponding methods then we can collect these objects
together and treat them identically in our program but
the objects will behave differently. This ability to
behave differently to the same input messages is known
as polymorphism. ...

...

Inheritance is often used as a mechanism to implement
polymorphism. Indeed in many OO languages it is the only
way to implement polymorphism. It works as follows:

A class can inherit both attributes and operations from
a parent or super class. This means that a new class which
is identical to another class in most respects does not
need to reimplement all the methods of the existing class,
rather it can inherit those capabilities and then override
those that it wants to do differently (like the paint
method in the case above)

------------------------------

> *function
A function is one type of moduile at the computer theory level,
although in Python they are two diffeent things...

------------

The role of modular programming is to allow the programmer to
extend the built in capabilities of the language. It packages
up bits of program into modules that we can 'plug in' to our
programs. The first form of module was the subroutine which
was a block of code that you could jump to (rather like the
GOTO mentioned in the branching section) but when the block
completed, it could jump back to wherever it was called from.
That specific style of modularity is known as a procedure
or function.

-----------------


> *local variable
> *global variable

Actually I don't explain this well in the web tutor and only
slightly better in the book! I'll need to do a bit more here.
What I do say is:
------------------
 In Python there are only ever 3 namespaces (or scopes):
  1.. Local scope - names defined within a function or method
  2.. Module scope - names defined within a file
  3.. Builtin scope - names defined within Python itself are always
available.
----------------

> And if they do explain, its in programmers language
> that i cant understand :P.

THats what I'm trying to avoid so if I'm not succeeding please let
me know(theres a mail me link at the bottom of every page!). Its
only by being made aware of deficiencies that I can improve it.
This list helps enormously by highlighting FAQs but specific
areas of improvement are best highlighted by specific emails.

> things get more intense and programming lingo steps up
> a notch also.

That is inevitable, as jargon gets introduced it gets used.
Thats what its there for and part of the work of learning
any skill is learning(ie memorizing!) the meaning of jargon
terms. But if the initial explamnationi is inadequate please
shout don't suffer in silence!

> Sorry about the long post.  wanted to explain so you
> can understand the level i am at.

Please do , thats what this list (and my tutor) is there for.

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