[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: general question (different between methods and functions)?

David Vallner

3/28/2007 10:42:00 PM

Yamal Khaled Soueidan wrote:
> Hello everyone,
>
> I have been discussing the difference between methods and functions with a
> friend, but we couldn't agree on what method and function is?
>

Potayto, potahto.

Both are names for an abstraction over some bit of code that has Stuff
Going In and Stuff Going Out. For methods, commonly, what bit of code
gets executed depends on one of the things going in - some form of
polymorphic dispatch depending on an argument (this, in Ruby, being the
implicit self), and most commonly, on the type of this argument.

Of course, in Ruby, the type of self is -really- a Class object holding
a hash of methods. So the polymorphic dispatch depends on what's
actually some special value in the type system. Doing away with the
"special" role of self.class, we might as well say that if you put
lambdas (which seem function -ish enough) in a hash and then call one
depending on some value (a key in this hash), you're making a method
call (HI MR. GRAHAM!).

Going ad absurdum, if we accept that a "method" is anytime when
semantics of a message send / function call / etc. depends on the value
of an argument (or more (yay CLOS, the inexhaustible source of obscure
views on OO (and nested parens))), you could as well argue that OCaml
pattern matching is a form of polymorphic dispatch, making OCaml
functions methods. (Good luck trying to persuade those guys about that
without getting weird looks and getting asked "And this is important why?")

My $0.02 say that the distinction made more sense in C++, and keeping
both lingos was implementation details leaking into language syntax
leaking into programmer mindset, or in another language where a
polymorphic dispatch was a more ostentatious affair (Smalltalkesque "we
do it everywhere!"), and where noone bothered to think just how common
and trivial what's happening under the hood (a table lookup of one sort
of another) is.

David Vallner
End Rant

1 Answer

Chris Carter

3/29/2007 12:15:00 PM

0

On 3/28/07, David Vallner <david@vallner.net> wrote:
> Yamal Khaled Soueidan wrote:
> > Hello everyone,
> >
> > I have been discussing the difference between methods and functions with a
> > friend, but we couldn't agree on what method and function is?
> >
>
> Potayto, potahto.
>
> Both are names for an abstraction over some bit of code that has Stuff
> Going In and Stuff Going Out. For methods, commonly, what bit of code
> gets executed depends on one of the things going in - some form of
> polymorphic dispatch depending on an argument (this, in Ruby, being the
> implicit self), and most commonly, on the type of this argument.
>
> Of course, in Ruby, the type of self is -really- a Class object holding
> a hash of methods. So the polymorphic dispatch depends on what's
> actually some special value in the type system. Doing away with the
> "special" role of self.class, we might as well say that if you put
> lambdas (which seem function -ish enough) in a hash and then call one
> depending on some value (a key in this hash), you're making a method
> call (HI MR. GRAHAM!).


something like this? :
http://pastie.cabo...

>
> Going ad absurdum, if we accept that a "method" is anytime when
> semantics of a message send / function call / etc. depends on the value
> of an argument (or more (yay CLOS, the inexhaustible source of obscure
> views on OO (and nested parens))), you could as well argue that OCaml
> pattern matching is a form of polymorphic dispatch, making OCaml
> functions methods. (Good luck trying to persuade those guys about that
> without getting weird looks and getting asked "And this is important why?")
>
> My $0.02 say that the distinction made more sense in C++, and keeping
> both lingos was implementation details leaking into language syntax
> leaking into programmer mindset, or in another language where a
> polymorphic dispatch was a more ostentatious affair (Smalltalkesque "we
> do it everywhere!"), and where noone bothered to think just how common
> and trivial what's happening under the hood (a table lookup of one sort
> of another) is.
>
> David Vallner
> End Rant
>
>
>


--
Chris Carter
concentrationstudios.com
brynmawrcs.com