<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python Decorators in Ruby</title>
	<atom:link href="http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/</link>
	<description>Random Geek-Related Thoughts</description>
	<lastBuildDate>Tue, 16 Mar 2010 14:46:49 -0700</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nicolas Lara</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-17350</link>
		<dc:creator>Nicolas Lara</dc:creator>
		<pubDate>Tue, 10 Nov 2009 19:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-17350</guid>
		<description>I wrote a similar piece (but backwards) on emulating ruby that you might like:
http://nicolas-lara.blogspot.com/2009/01/emulating-ruby-blocks-in-python.html</description>
		<content:encoded><![CDATA[<p>I wrote a similar piece (but backwards) on emulating ruby that you might like:<br />
<a href="http://nicolas-lara.blogspot.com/2009/01/emulating-ruby-blocks-in-python.html" rel="nofollow">http://nicolas-lara.blogspot.com/2009/01/emulating-ruby-blocks-in-python.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liusong1111</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16934</link>
		<dc:creator>liusong1111</dc:creator>
		<pubDate>Sun, 02 Aug 2009 11:24:38 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16934</guid>
		<description>Acctually, I didn&#039;t see any ruby web framework treat HttpRequest well.
merb-action-args make one step.
but, HttpParamSchema is so common, that reflect HtmlForm generation, URL generation, Http Params acceptance, validation, type-cast, transformation to poro...

need ActionForm or HttpParams come to rescue?</description>
		<content:encoded><![CDATA[<p>Acctually, I didn&#8217;t see any ruby web framework treat HttpRequest well.<br />
merb-action-args make one step.<br />
but, HttpParamSchema is so common, that reflect HtmlForm generation, URL generation, Http Params acceptance, validation, type-cast, transformation to poro&#8230;</p>
<p>need ActionForm or HttpParams come to rescue?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liusong1111</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16933</link>
		<dc:creator>liusong1111</dc:creator>
		<pubDate>Sun, 02 Aug 2009 11:13:18 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16933</guid>
		<description>Good job!
Introduce decorators to ruby make sense.

question:
1. UnboundMethod#name is not available in ruby1.8.6(seems 1.8.7 is ok).
   That&#039;s annoying especially I want to record decorators&#039; information as metadata, method name as key.
2. how to chain decorator&#039;s result?
  ruby_decorator return the last decorator&#039;s result. 
  but, unlike extlib#Hook, it doesn&#039;t pass result to chain. sinatra use throw keyword to archieve it. 
  
decorators may be helpful in losts situations, and Python&#039;s @ signal makes sense.

think about alter webframework like sinatra:

Post &quot;/articles&quot;
Param :subject, String
Param :body, Text
Respond :html, :json
def create
  ...
end</description>
		<content:encoded><![CDATA[<p>Good job!<br />
Introduce decorators to ruby make sense.</p>
<p>question:<br />
1. UnboundMethod#name is not available in ruby1.8.6(seems 1.8.7 is ok).<br />
   That&#8217;s annoying especially I want to record decorators&#8217; information as metadata, method name as key.<br />
2. how to chain decorator&#8217;s result?<br />
  ruby_decorator return the last decorator&#8217;s result.<br />
  but, unlike extlib#Hook, it doesn&#8217;t pass result to chain. sinatra use throw keyword to archieve it. </p>
<p>decorators may be helpful in losts situations, and Python&#8217;s @ signal makes sense.</p>
<p>think about alter webframework like sinatra:</p>
<p>Post &#8220;/articles&#8221;<br />
Param :subject, String<br />
Param :body, Text<br />
Respond :html, :json<br />
def create<br />
  &#8230;<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: giorgi</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16911</link>
		<dc:creator>giorgi</dc:creator>
		<pubDate>Thu, 30 Jul 2009 10:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16911</guid>
		<description>Let me re-iterate that, to use decorators, one does not need to reshape Python interpreter; use of DecoratorTools (http://peak.telecommunity.com/DevCenter/DecoratorTools) perfectly suffices:

from peak.util.decorators import decorate

class Demo1(object):
    decorate(a_classmethod)   # equivalent to @a_classmethod
    def example(cls):
        print &quot;hello from&quot;, cls</description>
		<content:encoded><![CDATA[<p>Let me re-iterate that, to use decorators, one does not need to reshape Python interpreter; use of DecoratorTools (<a href="http://peak.telecommunity.com/DevCenter/DecoratorTools" rel="nofollow">http://peak.telecommunity.com/DevCenter/DecoratorTools</a>) perfectly suffices:</p>
<p>from peak.util.decorators import decorate</p>
<p>class Demo1(object):<br />
    decorate(a_classmethod)   # equivalent to @a_classmethod<br />
    def example(cls):<br />
        print &#8220;hello from&#8221;, cls</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: smallpaul</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16886</link>
		<dc:creator>smallpaul</dc:creator>
		<pubDate>Sat, 25 Jul 2009 14:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16886</guid>
		<description>I think that there is some disingenuousness on both sides of this argument.

If language &quot;A&quot; must implement a feature in C code and language &quot;B&quot; can implement it in language B itself, then yes language &quot;B&quot; is more flexible. In this case the claim is that Ruby is more flexible than Python, which is true if this decorator syntax does what is described. No, it is not &quot;the same thing&quot; to use the inconvenient pre-Python syntax. If that syntax were sufficient then Python would never have added decorators to the language. It is to Ruby&#039;s credit if it can implement the modern Python syntax without changing the Python interpreter.

So that&#039;s the disingenuousness on the Python side. If the blog post does what it does, then it is impressive and to Ruby&#039;s credit.

On the Ruby side, I want to be sure that we are talking about something truly analogous to Pythons decorators.

 * When I tried to use this construct in an ActiveRecord model, the model stopped working, even before I added any decorated methods. Is that expected? That does not happen with Python decorators.

 * Based on my experience above, I believe that if I added this globally, I would break a lot of Rails or Merb code. You implied in the blog post that it was fairly discretionary whether to add it to every class in the system, but I&#039;d appreciate it if you could be explicit about how safe this is or is not.

 * It is not clear to me how I apply this to lambda or &quot;top-level&quot; functions

 * It is not clear to me how I decorate attr_accessors. Will it work to just put the decorator before the attr_accessor line?

 * Does decoration of class methods &quot;just work&quot; as I&#039;d expect?

 * Can I decorate classes? Ruby classes are callable, so they should be decoratable.

Once I understand these issues better I&#039;ll be able to know whether this is truly equivalent to the Python feature or just a neat hack that emulates it in simplistic cases.

Before Python got decorator syntax, the convention for decorating was consistent across functions, methods, anonymous functions and classes. In Python 3 it is again consistent for all of those constructs. (for a while in Python 2.x classes were excluded for no good reason) Therefore I believe that Python&#039;s syntax is much more general purpose than the one you&#039;ve demonstrated here.</description>
		<content:encoded><![CDATA[<p>I think that there is some disingenuousness on both sides of this argument.</p>
<p>If language &#8220;A&#8221; must implement a feature in C code and language &#8220;B&#8221; can implement it in language B itself, then yes language &#8220;B&#8221; is more flexible. In this case the claim is that Ruby is more flexible than Python, which is true if this decorator syntax does what is described. No, it is not &#8220;the same thing&#8221; to use the inconvenient pre-Python syntax. If that syntax were sufficient then Python would never have added decorators to the language. It is to Ruby&#8217;s credit if it can implement the modern Python syntax without changing the Python interpreter.</p>
<p>So that&#8217;s the disingenuousness on the Python side. If the blog post does what it does, then it is impressive and to Ruby&#8217;s credit.</p>
<p>On the Ruby side, I want to be sure that we are talking about something truly analogous to Pythons decorators.</p>
<p> * When I tried to use this construct in an ActiveRecord model, the model stopped working, even before I added any decorated methods. Is that expected? That does not happen with Python decorators.</p>
<p> * Based on my experience above, I believe that if I added this globally, I would break a lot of Rails or Merb code. You implied in the blog post that it was fairly discretionary whether to add it to every class in the system, but I&#8217;d appreciate it if you could be explicit about how safe this is or is not.</p>
<p> * It is not clear to me how I apply this to lambda or &#8220;top-level&#8221; functions</p>
<p> * It is not clear to me how I decorate attr_accessors. Will it work to just put the decorator before the attr_accessor line?</p>
<p> * Does decoration of class methods &#8220;just work&#8221; as I&#8217;d expect?</p>
<p> * Can I decorate classes? Ruby classes are callable, so they should be decoratable.</p>
<p>Once I understand these issues better I&#8217;ll be able to know whether this is truly equivalent to the Python feature or just a neat hack that emulates it in simplistic cases.</p>
<p>Before Python got decorator syntax, the convention for decorating was consistent across functions, methods, anonymous functions and classes. In Python 3 it is again consistent for all of those constructs. (for a while in Python 2.x classes were excluded for no good reason) Therefore I believe that Python&#8217;s syntax is much more general purpose than the one you&#8217;ve demonstrated here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cyril David</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16850</link>
		<dc:creator>Cyril David</dc:creator>
		<pubDate>Mon, 20 Jul 2009 12:21:32 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16850</guid>
		<description>Reading through the comments, it&#039;s just way too hilarious to see all the defensive comments, repetitive false arguments in favor of python. It&#039;s like Yehuda&#039;s words are falling on deaf ears o-O

Great post.</description>
		<content:encoded><![CDATA[<p>Reading through the comments, it&#8217;s just way too hilarious to see all the defensive comments, repetitive false arguments in favor of python. It&#8217;s like Yehuda&#8217;s words are falling on deaf ears o-O</p>
<p>Great post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jedediah Smith</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16829</link>
		<dc:creator>Jedediah Smith</dc:creator>
		<pubDate>Sun, 19 Jul 2009 11:40:43 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16829</guid>
		<description>What bothers me about the Python philosophy is that it is based on fear. If the language never allowed magical meta-programming, how can anyone be sure it is such a bad thing?

The speculation that such features lead to obfuscated code makes sense in theory, but Ruby has shown that in practice, the opposite is true: a more flexible language allows the programmer to be more *expressive* and the code to communicate its meaning more *concisely*.

Of course, in the hands of a bad programmer, these features can be used to make a mess, as can any other powerful feature. But crippling languages to limit the damage done by incompetents is ultimately self-defeating. It&#039;s much easier to just take away their keyboards.</description>
		<content:encoded><![CDATA[<p>What bothers me about the Python philosophy is that it is based on fear. If the language never allowed magical meta-programming, how can anyone be sure it is such a bad thing?</p>
<p>The speculation that such features lead to obfuscated code makes sense in theory, but Ruby has shown that in practice, the opposite is true: a more flexible language allows the programmer to be more *expressive* and the code to communicate its meaning more *concisely*.</p>
<p>Of course, in the hands of a bad programmer, these features can be used to make a mess, as can any other powerful feature. But crippling languages to limit the damage done by incompetents is ultimately self-defeating. It&#8217;s much easier to just take away their keyboards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paddy3118</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16760</link>
		<dc:creator>Paddy3118</dc:creator>
		<pubDate>Wed, 15 Jul 2009 21:13:14 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16760</guid>
		<description>Aaaahhh...

If only more such language comparison threads were this civilised. Hats off to you all folks.</description>
		<content:encoded><![CDATA[<p>Aaaahhh&#8230;</p>
<p>If only more such language comparison threads were this civilised. Hats off to you all folks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Segal</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16759</link>
		<dc:creator>Loren Segal</dc:creator>
		<pubDate>Wed, 15 Jul 2009 17:49:23 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16759</guid>
		<description>@giorgi

I know about the difference between __getattr__ and __getattribute__, the code I posted emulates this fine. The implementation will check if the call is an attribute (instance variable) only-- you can continue in the else block for pure __getattr__ behaviour.</description>
		<content:encoded><![CDATA[<p>@giorgi</p>
<p>I know about the difference between __getattr__ and __getattribute__, the code I posted emulates this fine. The implementation will check if the call is an attribute (instance variable) only&#8211; you can continue in the else block for pure __getattr__ behaviour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgi</title>
		<link>http://yehudakatz.com/2009/07/11/python-decorators-in-ruby/comment-page-1/#comment-16758</link>
		<dc:creator>Giorgi</dc:creator>
		<pubDate>Wed, 15 Jul 2009 07:18:23 +0000</pubDate>
		<guid isPermaLink="false">http://yehudakatz.com/?p=294#comment-16758</guid>
		<description>@Loren Segal
Just for the seek if illustration: the closest analog of Ruby for Python&#039;s &#039;__getattribute__&#039; is, probably, #send.
class Object
    alias :old_send :send
    def send(sym)
        #do something with sym, e.g., get a &quot;descriptor&quot; class via sym and handle it
        #call old_send
        b=old_send sym
        #do something with b and return
        b
    end
end
Therefore, I would like to maintain that the most significant difference between Ruby and Python is the accents the communities put on the language features (i.e., the choice of features for &quot;daily&quot; use) not the features themselves. The latter can be easily emulated.
Another example is re-opening classes. In Python, it&#039;s perfectly possible, but seldom used; in Ruby, re-opening a class is pretty common. In Ruby, customization of the protocol receiver handles a message seems to be easy, but I have not seen an example of it in a real code; in Python, vice versa, customization of the protocol an object interacts with the members of the object dict is truly pythonic, and so on.</description>
		<content:encoded><![CDATA[<p>@Loren Segal<br />
Just for the seek if illustration: the closest analog of Ruby for Python&#8217;s &#8216;__getattribute__&#8217; is, probably, #send.<br />
class Object<br />
    alias :old_send :send<br />
    def send(sym)<br />
        #do something with sym, e.g., get a &#8220;descriptor&#8221; class via sym and handle it<br />
        #call old_send<br />
        b=old_send sym<br />
        #do something with b and return<br />
        b<br />
    end<br />
end<br />
Therefore, I would like to maintain that the most significant difference between Ruby and Python is the accents the communities put on the language features (i.e., the choice of features for &#8220;daily&#8221; use) not the features themselves. The latter can be easily emulated.<br />
Another example is re-opening classes. In Python, it&#8217;s perfectly possible, but seldom used; in Ruby, re-opening a class is pretty common. In Ruby, customization of the protocol receiver handles a message seems to be easy, but I have not seen an example of it in a real code; in Python, vice versa, customization of the protocol an object interacts with the members of the object dict is truly pythonic, and so on.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
