RE: Python, Possibly OO, Terminology Question

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 29 Jul 2011 19:54:23 -0400

I agree as I said before I use function for most anything like a function.
The point I am trying to so badly make is knowing what you are talking about
is important so at least getting close is important.


Ken

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of David Tseng
Sent: Friday, July 29, 2011 5:46 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Python, Possibly OO, Terminology Question

Right, but if you bind it to say window....
window.SimpleArith = SimpleArith

within the closure, you actually bind the "function" to the window's
scope and thus accessible outside of the empty namespace.

I'm not disagreeing with you, just trying to say that I don't think
there's a precise definition for the terms everyone's throwing out
there.  They're very soft terms for some real and well-defined
concepts.

On 7/29/11, Ken Perry <whistler@xxxxxxxxxxxxx> wrote:
>
> What that is called is javascript enclosure functions that is my point
> though you need to understand what they are so if you say it's a class
> function then it's really a method but if it's a function as you just did
> it's an enclosed function.  Words do mean things and to say just call them
> all functions because they are the same thing is wrong.  For example if I
> did what you did below and told someone I wrote a function they would be
> shocked to find they couldn't access it because I didn't tell them it was
> enclosed.
>
> ken
>
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of David Tseng
> Sent: Friday, July 29, 2011 5:00 PM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: Re: Python, Possibly OO, Terminology Question
>
> Call it whatever you want...as long as you have a firm grasp of the
> underlying concepts relating to OOP or functional programming, you'll
> be just fine.
>
> Tell me what the following is:
> function () {
>   function SimpleArith() {
>     'Add': function(a,b) { return a + b; },
>     'Sub': function(a,b) { return a - b; },
>     'PI':3.14,
>   };
> };
>
> function Compute(a,b) {...}
>
> They're all called functions...namespaces, classes, methods, functions...
>
> On 7/29/11, Ken Perry <whistler@xxxxxxxxxxxxx> wrote:
>> I will say one more thing.  If you search for this "difference between
>> function and method"  you will find lots of people that will argue this
>> point over and over.  In fact you will find most of them that say it
don't
>> matter but I want to drop some code right here.  There is one language
> that
>> definitely is both functional and object oriented and that is c++ so look
> at
>> this code
>>
>> Class  myClass{
>> Int b=0;
>> Void aThing(int a){b=a};
>> }
>>
>> Int b=0;
>> Void aThing(int a){
>> B=a;
>> }
>>
>> Now to use the aThing in the first you must instantiate the class and use
> it
>> from the class to use the second aThing you don't have to.  One is called
> a
>> function to distinguish it from the other.  It's still a function but
it's
> a
>> method because it's part of a classs.  So go ahead call it whatever you
> like
>> but the fact is there is a major difference.  Not only is there a
> difference
>> but it matters in languages when you have both functional and objects in
> the
>> same language because the top two could be in the same program in the
same
>> c++ file and they are different.
>>
>> ken
>>
>>
>> -----Original Message-----
>> From: programmingblind-bounce@xxxxxxxxxxxxx
>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Johannes Grib
>> Sent: Friday, July 29, 2011 6:45 AM
>> To: programmingblind@xxxxxxxxxxxxx
>> Subject: RE: Python, Possibly OO, Terminology Question
>>
>> Hi Ken PerryPerry,
>> Perhaps you might want to cite references please as documentation state
> the
>> following:
>>
>>
>> The class contains the methods. A method is a function or module that is
>> owned by the class. Depending on the programming language you're using,
>> method, function, module, subroutine may all be used interchangeably.
>>
>> This supports Kerneels's "wrong" answer.
>>
>> Kindest
>> Johannes
>>
>>
>>
>> -----Original Message-----
>> From: programmingblind-bounce@xxxxxxxxxxxxx
>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ken Perry
>> Sent: Friday, July 29, 2011 12:29
>> To: programmingblind@xxxxxxxxxxxxx
>> Subject: RE: Python, Possibly OO, Terminology Question
>>
>>
>> Well if you want me to I will
>> You said,
>> "> in fact want to distinguish between them you could use "method" for
>>> something that doesn't return anything (a void function) and use
>>> "function" when something is returned, but it really doesn't matter
>>> much since it's just documentation particulars."
>>
>> That was wrong that is the descriptions between a procedure and an
> function
>> like I said in my email.  Also there is a difference between function and
>> method it's not just a documentation thing another wrong statement. For
>> example it would be the same thing saying a member is the same thing as a
>> class.  While a member of a class is a  variable it is a variable
attached
>> to a class as a method is a function attached to a class.
>>
>>
>> -----Original Message-----
>> From: programmingblind-bounce@xxxxxxxxxxxxx
>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Kerneels Roos
>> Sent: Friday, July 29, 2011 3:34 AM
>> To: programmingblind@xxxxxxxxxxxxx
>> Subject: Re: Python, Possibly OO, Terminology Question
>>
>> I did say "please correct me if I'm wrong" but I was referring to the
>> Python stuff really. So where is my answer wrong please? I don't think
>> my answer was a wrong or right kind of answer actually -- it's about
>> preference and style (excluding the Python specifics).
>>
>> Also made it quite clear that it doesn't really matter if you use the
>> term "method" or "function" since they are used interchangeably and mean
>> the same thing, or more importantly, you can't draw any serious
>> conclusion if someone uses one or the other right?
>>
>> Simply saying "the previous answer is wrong" is too vague for me at
>> leastThe statement about procedures, that we used to call functions that
>> didn't return anything "procedures" -- yeah, I can remember that from
>> Pascal also. Wasn't it the case that if you used the keyword "Procedure"
>> you couldn't return anything, while when you used "Function" you were
>> forced to return something?
>> Thanks for pointing that out.
>>
>> Maybe it's one of those things there is no true consensus about? Would
>> any "real" professor venture a comment here?
>>
>> Regards
>>
>> On 7/28/2011 2:19 PM, Ken Perry wrote:
>>>
>>> The previous answer was wrong.  We used to call functions that return
>>> nothing a procedure but that is in languages like pascal but the
> following
>>> is the real answer for what is a function verses method.
>>>
>>> A function is a piece of code that is called by name. It can be passed
>> data
>>> to operate on (ie. the parameters) and can optionally return data (the
>>> return value).
>>>
>>> All data that is passed to a function is explicitly passed.
>>>
>>> A method is a piece of code that is called by name that is associated
> with
>>> an object. In most respects it is identical to a function except for two
>> key
>>> differences.
>>>
>>>
>>> -----Original Message-----
>>> From: programmingblind-bounce@xxxxxxxxxxxxx
>>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
>>> Sent: Thursday, July 28, 2011 6:59 AM
>>> To: programmingblind@xxxxxxxxxxxxx
>>> Subject: RE: Python, Possibly OO, Terminology Question
>>>
>>> Hi All,
>>> Thanks for trying to answer. I'll just keep coding and eventually I'll
>>> either understand or not.
>>>
>>> Jim
>>>
>>> -----Original Message-----
>>> From: programmingblind-bounce@xxxxxxxxxxxxx
>>> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Kerneels
Roos
>>> Sent: Thursday, July 28, 2011 3:48 AM
>>> To: programmingblind@xxxxxxxxxxxxx
>>> Subject: Re: Python, Possibly OO, Terminology Question
>>>
>>> Jim, and otheres, I agree that "method" and "function" are used
>>> interchangeably and mean the same thing usually, but I think if you do
>>> in fact want to distiguish between them you could use "method" for
>>> something that doesn't return anything (a void function) and use
>>> "function" when something is returned, but it really doesn't matter much
>>> since it's just documentation particulars.
>>>
>>> In OO terminology people seem to prefer method over function (in my
>>> experience).
>>>
>>> What is more important is to understand the difference between class and
>>> instance methods, which, coming from Java such as yourself is simple to
>>> grasp. In computer science it helps to distinguish terminology from
>>> implementation particulars since languages can and do use varied terms
>>> for intrinsically the same thing. Some times the language uses the right
>>> terminology, or the most widely accepted terminology, but ti's not a
>> given.
>>>
>>> Now, to get back to Python, it seems there are three types of methods
>>> (and please correct me here if I'm wrong):
>>>
>>> @staticmethod
>>> def some_static_method (param1, param2):
>>>       # do something not involving an instance of the class this method
>>> is in, except other static items perhaps
>>>
>>> So this looks like the class method (OO terminology) which you get in
>>> Java by adding the "static" method attribute to your method is it not?
>>>
>>> @classmethod
>>> def some_class_method (cls):
>>>       # ?? how is this different to @staticmethod ??
>>>
>>> Please explain the above.
>>>
>>> def some_instance_method (self, param1, param2):
>>>       # can use self. here to reference the instance of the class
>>>
>>>
>>> This is the normal method you get with Java without adding "static" to
>>> the method signiture, so a standard instance method in Java would be the
>>> equivalent of this?
>>>
>>>
>>> Regards
>>>
>>>
>>>
>>> On 7/27/2011 11:42 PM, David Tseng wrote:
>>>> For the purists out there, classes, functions, methods, procedures,
>>>> etc are all sort of related.  You can think of a class as a function
>>>> in python with some setup/teardown facilities, a closure, and a symbol
>>>> table mapping it's instance variables/functions.  I don't think any
>>>> language shows this better than javascript, but python comes pretty
>>>> close.
>>>>
>>>> But, I think Jamal's right Jim, you should just dive in and see how
>>>> things behave in practice and stop letting me and others confuse you
>>>> :).
>>>>
>>>> On 7/27/11, Q<q@xxxxxxxxxxxxxxxxxx>   wrote:
>>>>> Okay. First, everything is an object as you mentioned. This is
>>>>> somewhat-important.
>>>>> Now, functions vs. methods.
>>>>> Generally in Python function means standalone callable. When I say
>>>>> callable, I'm referring to an object which has a __call__ method.  So
>>>>> when it comes down to it, functions are simply objects that define
>>>>> __call__. But of course, we generally don't create these function
>>>>> objects manually. That's just what happens when the interpreter reads
> in
>>>>> a def block.
>>>>> So, a function is a regular callable that does not take an instance as
>>>>> its first argument.
>>>>> def test():
>>>>>     print "hello, world!"
>>>>>
>>>>> While you could attach these types of functions to a class:
>>>>> class Tester(object):
>>>>>     pass
>>>>>
>>>>> Tester.test = test
>>>>>
>>>>> note what happens when you instantiate that class and try to use them:
>>>>> t=Tester()
>>>>> t.test()
>>>>> TypeError: test() takes no arguments (1 given)
>>>>> Because Python tries to pass the class instance in as the first
> argument
>>>>> to that function, and it takes none.
>>>>> Now, there's absolutely no reason you couldn't do something like:
>>>>> def other_test(self):
>>>>>     print "Hi there!"
>>>>>
>>>>> and attach other_test to Tester.
>>>>> And this would actually work just fine. It wouldn't be a true method
>>>>> object, which has a couple of other attributes on it (try dir on a
>>>>> function object and a method object for comparison)
>>>>> Now, you mentioned static methods. How we create these is with the
>>>>> staticmethod decorator.
>>>>> Observe:
>>>>>
>>>>> class SomeClassWithStaticMethods(object):
>>>>>
>>>>>     @staticmethod
>>>>>     def something_inside_the_class_namespace():
>>>>>      return "I was called!"
>>>>>
>>>>> You can call this static method on any class object or instance. So
you
>>>>> could go
>>>>>
>>>>> SomeClassWithStaticMethods.something_inside_the_class_namespace()
>>>>> or
>>>>> c = SomeClassWithStaticMethods()
>>>>> c.something_inside_the_class_namespace()
>>>>>
>>>>> but this is rarely-needed, generally better is putting a regular
>>>>> function inside the class's module. This would only be required if you
>>>>> explicitly want to have the function inside the class namespace, I.E.
a
>>>>> module with several unrelated classes.
>>>>> Then, we have class methods, marked with the @classmethod decorator.
>>>>> These are extremely-useful. They operate on class objects instead of
>>>>> instance objects.
>>>>>
>>>>> class Something(object):
>>>>>
>>>>>     @classmethod
>>>>>     def do_funky_things_to_the_class(cls):
>>>>>      #You could do all kinds of hackery in here on the class object
>> before
>>>>> its already instantiated or whatever. cls contains the class object,
> and
>>>>> it's conventional to use cls in this case where self is for instance
>>>>> methods.
>>>>>      cls.some_attribute = 1 #all instances of this class will have
>>>>> some_attribute set to 1 if you call this
>>>>>
>>>>> I hope this untangles things a little. If you don't understand
anything
>>>>> feel free to ask, but do do a lot of exploration with dir. also check
>>>>> out the inspect module to let you poke around at the internals and see
>>>>> what's going on a bit under the covers.
>>>>> And if I'm mistaken about anything here, someone on list please-do
>>>>> correct me as this is all stuff I've derived from usage.
>>>>>
>>>>>         Q
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 7/27/2011 4:07 PM, Jamal Mazrui wrote:
>>>>>> Yes, I think a function at the module level in Python is like a
static
>>>>>> method of that module.  The module, moreover, is like a singleton
>>> object.
>>>>>> Although these nuances can be interesting to discuss, let me
encourage
>>>>>> folks not to get hung up on terminology, thinking that one cannot
code
>>>>>> productively until certain theory or terminology is mastered.  I say
>>>>>> try to understand as much theory as one can at the time, but then set
>>>>>> aside a solid grasp of some aspects for now if they seems elusive.
>>>>>>
>>>>>> I think that learning is usually best achieved through an iterative
>>>>>> process that involves both learning and applying ideas.  If one
>>>>>> postpones actual application, there is only so far that one's
>>>>>> understanding can go.  On the other hand, after experiencing the
>>>>>> results of applied understanding, one can try to learn more, apply it
>>>>>> in code, debug, regroup, etc.
>>>>>>
>>>>>> Jamal
>>>>>>
>>>>>> On 7/27/2011 3:45 PM, Homme, James wrote:
>>>>>>> Hi,
>>>>>>> Forgot to copy the list. This sounds like static methods in other
>>>>>>> languages. Is that anywhere in the universe?
>>>>>>>
>>>>>>> Jim
>>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: David Tseng [mailto:davidct1209@xxxxxxxxx]
>>>>>>> Sent: Wednesday, July 27, 2011 3:40 PM
>>>>>>> To: programmingblind@xxxxxxxxxxxxx
>>>>>>> Cc: Homme, James
>>>>>>> Subject: Re: Python, Possibly OO, Terminology Question
>>>>>>>
>>>>>>> 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
>>>>>>>
>>>>>>>
>>>>>> __________
>>>>>> 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
>>>>>
>>>>>
>>>> __________
>>>> View the list's information and change your settings at
>>>> //www.freelists.org/list/programmingblind
>>>>
>>
>> --
>> Kerneels Roos
>> Cell: +27 (0)82 309 1998
>> Skype: cornelis.roos
>>
>> __________
>> 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
>>
>> __________
>> 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
>>
>>
> __________
> 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
>
>
__________
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: