News for hackers. Stuff that matters.
Re:Python vs Ruby, slightly more in-depth by didip on Tuesday August 04, 2009 @05:16PM (#742218)
Visitor patterns add new functionality to existing object structure [http://en.wikipedia.org/wiki/Visitor_pattern].

Python decorator does not do that?

Re:Python vs Ruby, slightly more in-depth by tetha on Tuesday August 04, 2009 @06:10PM (#742316)
The decorator syntax

  @decorator2
  @decorator1
  def foo(*args):
      pass
is just a shorthand for

  def foo(*args):
      pass
  foo = decorator2(decorator1(foo))
I completely fail to see the visitor pattern here, even with stretching until breaking.
Re:Python vs Ruby, slightly more in-depth by didip on Tuesday August 04, 2009 @09:39PM (#742635)
Python decorator can do more than just that.

@decorator1 can be a completely different class which manipulate foo.__class__

Re:Python vs Ruby, slightly more in-depth by tetha on Wednesday August 05, 2009 @08:15AM (#743241)
Certainly, it is an arbitrary python function, so the resulting foo might be a dictionary or whatever. But this doesn't push it closer to the visitor pattern.

Certainly, you can use decorators as a tool to implement the visitor pattern by implementing some hairy, magical reflecting class-decorator which adds a method visit to an object, which then calls visit_{CLASSNAME} on the parameter, but this is just a way of implementing this and not the visitor pattern in itself.