[Tutor] RE: global vars vs. func args

Scott Widney SWidney@ci.las-vegas.nv.us
Mon, 11 Mar 2002 14:29:46 -0800


> The QPB also answered another question from above -- that 
> functions can be used as "subroutines", only that in Python 
> they're called "procedures" -- blocks of code that do not
> return a value.

Yep. Some other languages are a little more rigid with the terminology.

In one version of Beginner's All-purpose Symbolic Instruction Code, a
FUNCTION must return a value and a SUB-routine must not. So a FUNCTION is
used to generate a value that can be assigned to a variable. And a SUB is
simply used to perform a repetitive task (usually fraught with side
effects).

In another language (Pascal, I think?), a FUNCTION returns a value, and a
PROCEDURE does not. It's semantics.

In Python, when you DEFine a function, you're creating a name and
associating that name with a function object. Python is relaxed. You can
choose to return a value or not.

> Is this still legitimate coding practice in Python?  The QPB 
> is a bit dated, but this seems like valid use of functions.

Sure...use whatever you know now in whatever way is appropriate to getting
the task completed.

"Everything is permissible, but not all things are beneficial."

You can always refactor it, if it's going to be around for a while.

"The best thing about knowing the rules is knowing when to break them."

Incidentally, even when you don't specify a return value in your function
definition, it still returns a value (None). If you don't assign it to a
variable, or capture it in some other way, it just drops out.

</rambling>

Scott