Re: Python, Possibly OO, Terminology Question

  • From: David Tseng <davidct1209@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 27 Jul 2011 12:39:30 -0700

With respect to python's innate "object orientedness" where
everything's an object, you can think of functions and methods as
binding or associated with other objects.  A function or method that's
"associated" with a class object, takes the class object as its first
parameter as you stated.  However, you can just as easily bind a
function or method to a class without that first "self" parameter.
The distinction lies in what the function or method is bound to.  In
the former, the function/method binds to an instance of that class
while the latter binds to the class itself.

For example,
class foo:
  def instance(self):
    pass

  def non_instance():
    pass

I'd encourage you to not take any of our words for it and try it out
yourself.  Try typing the follwing into an interpreter.
>>> foo.non_instance
>>> foo
>>> foo.instance
>>> f = foo()
>>> f.non_instance
>>> f.instance



On 7/27/11, Jamal Mazrui <empower@xxxxxxxxx> wrote:
> I think the terms function, method, procedure, subroutine, or code block
> are generally synonymous.  They refer to a programming construct that
> receives 0 or more parameters, executes code with those parameters as
> data, and then returns 0 or more result values.
>
> A particular term may be used to emphasize an aspect of the context
> under discussion.  For example, a method implies being an aspect of an
> object.  A subroutine implies that there is no meaningful return value.
>   A code block implies an in-line definition with access to surrounding
> variables.
>
> In general, however, I think there are not fine distinctions among these
> terms.
>
> Jamal
>
> On 7/27/2011 11:14 AM, Homme, James wrote:
>> Hi,
>>
>> I'm right at the point where I'm concerned about learning this the wrong
>> way, so I'm asking now before it's cemented into my head. Is it
>> appropriate to use the term function and the term method
>> interchangeably? If so, why? If not, why not? I realize that in Python,
>> when you have methods in the definition of a class, they always have
>> self as the first argument, so that helps you realize that you are
>> looking at a method. I also know that if you make a program that has no
>> classes in it, that you can use functions, and they don't look like they
>> are attached to a class, but one of the books I was looking at says that
>> everything in Python is an object, even if the code doesn't look like
>> that, but I'm trying to avoid dragging that into this discussion to
>> possibly artificially keep concepts separate in order to learn them.
>>
>> Thanks.
>>
>> Jim
>>
>> Jim Homme,
>>
>> Usability Services,
>>
>> Phone: 412-544-1810.
>>
>>
>> This e-mail and any attachments to it are confidential and are intended
>> solely for use of the individual or entity to whom they are addressed.
>> If you have received this e-mail in error, please notify the sender
>> immediately and then delete it. If you are not the intended recipient,
>> you must not keep, use, disclose, copy or distribute this e-mail without
>> the author's prior permission. The views expressed in this e-mail
>> message do not necessarily represent the views of Highmark Inc., its
>> subsidiaries, or affiliates.
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: