On 22/08/11 18:38, Lisi wrote:

technical terms.  I am still very confused by the terminology.  Having been
told that modules, functions and methods are just different names for the
same thing, that commands are really also the same thing and having had them
called yet a fifth thing in order "not to confuse you" (ouch!!)

I see Steven has sent a very good reply, I'll add a slightly different slant but try not to confuse things further!

There is a loty of confusion and double definitions in Computing, mainly through history and the evolution of different languages etc.

There is also the difference between a computing concept, like a module, and the implementation of that concept in a given language. In general the concept will be a broader definition than the implementation.

So sub-routine comers from the world of assembler programming and was adopted by BASIC because BASIC was invented back in the 1960's when most folks were used to assembler. Function comes from math and is directly related to the math theory behind computing and was therefore introduced into theoretical biased languages like Algol.

Modularity is a design concept from the world of engineering.
sub routines and functions were early attempts to introduce
modularity into the world of computing. Gradually modularity was extended to include concepts like code libraries of sub-routines/functions and eventually the term module started to appwear in programming languages themselves - Modula, (and then Modula 2 and Modula 3) being I think the main source.

Commands are slightly different in that they look quite similar to functions but usually have slightly different calling syntax and they are usually built into the core language rather than being user defined( but as always exceptions exist so that Tcl for example allows you to define your own commands) In Python 2 the best known command is print. It has been turned into a function in Python v3, thus

in v2

print "Hello"

becomes, in V3

print("Hello")

Notice the addition of parentheses.

So what does all that mean in practice in Python?

Modules are files that contain any kind of arbitrary
python code that can be imported into other programs
and reused.

Very often Modules contain one or more function definitions.

Modules can also contain class definitions - classes are
another mechanism for providing modularity (the concept!)
in programs. Class definitions also contain functions (with
the special classification "method" - see another thread)
within them.

> I am in a right muddle.

It is entirely understandable. This is one of the most
confusing areas of computing.

> ...  And I shall just go on asking questions until I have got the
whole thing disentangled in my head.  Sorry, everybody.

Don't apologise, it's the right thing to do. And on a list like this you will almost certainly clarify things in a lot of other folks heads too, who may not have thought through the complexities for themselves yet.

So now, can anyone suggest an example of a module to look at?  (Preferably
with some subroutines inside).It is clearly NOT just another name for
function or method.  I imagine that there are some on the Internet?

Look in the standard library at glob.py
It is one of the few that doesn't confuse things with classes, it is just a collection of functions and not too complicated ones at that. But being part of the standard library it has all the features that make a good reusable module too (documentation etc). And its not too big.

I hadn't actually counted the keystrokes.  I stand corrected.  But saving 6
keystrokes is still a fairly pointless thing to do.  If several subroutines
can be stored in a module and imported together, then that is quite another
matter.

Even a single function can be useful, since you only need to maintain it in one place even if its used in many projects.

But in general a module contains several (hopefully related) functions.
glob.py is a good example.

HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to