On Tue, Sep 04, 2001 at 06:01:31PM -0400, Amir Karger wrote:
[...]
> >   You can add a __cal__ method to a class making it a functor, and using it
> > everywhere a function can be used. I don't even dream it how to do it in
> > perl... ;-)
> 
> I'm *not* trying to start a flame war here. I'll point out, though, that you
> can overload operators in perl too. I don't really know what you mean about
> using a clas where you would use a function. I will say there's a *lot* of
> sneakiness that can be done with Perl classes -- mostly because it's very
> relaxed about requiring things -- although much of that may be obfuscated.
> The AUTOLOAD method is downright scary, for example. I recently bought
> Damian Conway [the guy who has written modules to write Perl in Klingon,
> Latin, and whitespace, among other things]'s "Object-Oriented Perl", where
> he seems to be arguing "anything you can do in [OO language X] I can do in
> Perl if I feel like it, but usually I won't bother." Or something. (But not
> in a condescending way. I think he's just hitting back at all the people who
> say Perl isn't a "real" OO language.)

  I'm not trying to continue a flame war either. :-)
  My point is the same as yours, I know that perl can do OO stuff. The point
in favour of python is that its syntax is very clean, and very easy to use.

  As an example consider this simple class that represents  a two dimensional vector.
  
class Vector:

  def __init__(self,initial_value=(0,0)):
    self.coord = initial_value
  
  def __add__(self,other):
    return Vector(self.coord[0]+other.coord[0],self.coord[1]+other.coord[1])
  
  def __str__(self):
    return str(self.coord)

a = Vector(1,2)
b = Vector(5,2)

print a,"+",b,"=",a+b

  I have defined a constructor, the adition and str (stringuify) for the
class. The __xxxx__ are special methods, but syntax is very readable. That's
one of the things I like... simplicity.

> -Amir

-- 
José

Reply via email to