On Feb 17, 5:39 pm, Steven D'Aprano <ste...@remove.this.cybersource.com.au> wrote: > On Wed, 17 Feb 2010 17:04:00 -0800, Jonathan Gardner wrote: > > (What the heck is a procedure, anyway? Is this different from a > > subroutine, a method, or a block?) > > The name is used in Pascal, which probably means it originated from > Fortran or Algol. > > A subroutine is a generic piece of code which can be re-used by some > unspecified mechanism (GOSUB in Basic, by calling it in most other > languages). A function is a subroutine that returns a result, and a > procedure is a subroutine that doesn't return anything (not even None, or > the equivalent thereof) and operates entirely by side-effect. >
Those are useful clarifications, but they are not completely universal. Some people make the definition of function more restrictive--"if it has side effects, it is not a function." Python's definition of a method is also not universal. In some circles, method is more akin to Steven's definition of a procedure--it does not necessarily have to be associated with a class. It's all very confusing, which is why Pythonistas are typically adamant about clarifying definitions within Python's context, which is understandable. To the extent that we're all talking about one programming language, we should use the same terms. A quick Google search does not turn up an official definition of a Ruby block, although the term "block" is colloquially used in both Python and Ruby to refer to a bunch of lines of code executed in a particular context, like a loop. Python may not support the broadest notion of anonymous functions, but it definitely has anonymous blocks. You can write this in Python: for i in range(10): print i print i * i print i * i * i Python does not force you to do this: def do_stuff(i): print i print i * i print i * i * i for i in range(10): do_stuff(i) -- http://mail.python.org/mailman/listinfo/python-list