[Tutor] modular programming help

kojo@hal-pc.org kojo@hal-pc.org
Fri, 8 Feb 2002 18:17:11 GMT


It seems to be primarily an issue of nomenclature <sp?> and convention varying 
between languages.

Modules/Subroutines/Functions are all similar, although different languages 
refer to them in different ways.

Here's my understanding of them in general, from a language-agnostic view:

Functions: Smallest of the three.  They tend to have just one purpose, like a 
good Unix tool (for those who know Unix).  They usually do one thing 
only...convert from $US to $Canadian; convert a string to Ascii; that sort of 
thing.  MOre of a One-step deal that you're going to need to do alot.

Subroutines: Larger and more complex than Functions.  May be made up of 
multiple Functions.  Usually perform more than one step on whatever they take 
in. (Take a binary number, convert it to Hex, find the HTML color for that hex 
value, print the name of the color).

Modules: Largest and most complex of the three.  Could easily be stand-alone 
(but limited use) programs.  Can also be called by other programs to provide 

Different languages use differnt terms for programming constructs similar to 
the ones above.  IIRC, Basic used Subroutines, Pascal says "Procedure" where 
Python might say "Function", and I'm not sure who besides us (Python) uses the 
term "Module".  All three can usually take an argument and return a value.

I think (and someone PLEASE jump in if I'm wrong so I don't confuse poor Cam) 
it's just a matter of figuring out what type of programming construct your 
teacher is discussing, in a more general sense.  Then you can learn the 
nomenclature used for the language you're learning.

It's like learning that Perl's Hash is Python's Dictionary.  Both are a mapping 
of some value to some key.

Oh, and sorry for any spelling errors.  I'm at work (temp job), so I'm using a 
web interface to my mail...No SpellChecker!!

Hope this helps,

> What I mean is Python uses files (name.py) as modules.  My intro to
> programming teacher in college is telling me that importing a file isn't
> calling a module.  I must be confussed here because I have always
> understood that modules were external programming things that you
> brought in with the import and then executed with functions from it what
> you wanted done.  Now this is how I use or understand modules in Python.
> You have some file called mod.py as a module.  It has a function in it
> called say printing.  This is what the function looks like:
> def printing(x):
>     return x
> Now to access this function I have to import it.
> import mod
> Then to use it:
> mod.printing("hello")
> Then there are the functions that return a 0, or a 1.  She says those
> are modules.  Example:
> def name(x):
>     if x >0
>         return 1
>     else:
>         return 0
> What is what here.  We're using Qbasic to understand how to do logic,
> but the terminology is tripping me up with Python.  She also said you
> should be able to pass values to modules and have them return values to
> you.  Functions in Python do that so she thought Python used the def to
> create procedures or subroutines.  I don't understand this Python idiom
> I guess.  
> A very confussed beginner,
> Cameron