<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: No need for set/get methods in Python</title>
	<atom:link href="http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/</link>
	<description>Simple is better than complex. Complex is better than complicated. &#124; @fedecarg</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:38:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-7282</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Mon, 15 Aug 2011 09:20:06 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-7282</guid>
		<description><![CDATA[Ruby and Python are both excellent programming languages.]]></description>
		<content:encoded><![CDATA[<p>Ruby and Python are both excellent programming languages.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: randomguest884</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-7278</link>
		<dc:creator><![CDATA[randomguest884]]></dc:creator>
		<pubDate>Thu, 11 Aug 2011 00:06:15 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-7278</guid>
		<description><![CDATA[&#039;syntactic nihilism&#039;
Cool, I&#039;ve got a new religion today...]]></description>
		<content:encoded><![CDATA[<p>&#8216;syntactic nihilism&#8217;<br />
Cool, I&#8217;ve got a new religion today&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-7186</link>
		<dc:creator><![CDATA[Jesse]]></dc:creator>
		<pubDate>Mon, 09 May 2011 12:05:20 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-7186</guid>
		<description><![CDATA[I love how the Ruby guy thinks his example of syntactic nihilism makes sense to anyone else.]]></description>
		<content:encoded><![CDATA[<p>I love how the Ruby guy thinks his example of syntactic nihilism makes sense to anyone else.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: amanita</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-2191</link>
		<dc:creator><![CDATA[amanita]]></dc:creator>
		<pubDate>Mon, 26 Jan 2009 13:38:27 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-2191</guid>
		<description><![CDATA[Instead of 
Book.title = &#039;Code Complete&#039;
shouldn&#039;t write:
book = Book()
book.title = &#039;Code Complete&#039;

With:
book._title = &#039;foo&#039;
I can modify the property from the outside anyway ... right?]]></description>
		<content:encoded><![CDATA[<p>Instead of<br />
Book.title = &#8216;Code Complete&#8217;<br />
shouldn&#8217;t write:<br />
book = Book()<br />
book.title = &#8216;Code Complete&#8217;</p>
<p>With:<br />
book._title = &#8216;foo&#8217;<br />
I can modify the property from the outside anyway &#8230; right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nisse</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1867</link>
		<dc:creator><![CDATA[Nisse]]></dc:creator>
		<pubDate>Wed, 29 Oct 2008 11:20:55 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1867</guid>
		<description><![CDATA[Well, those both seem obsolete after seeing how it&#039;s done in ruby.

class Book
  attr_accessor :title
end

which gives you

book = Book.new
book.title = &#039;rftw&#039;
puts book.title # =&gt; &quot;rftw&quot;]]></description>
		<content:encoded><![CDATA[<p>Well, those both seem obsolete after seeing how it&#8217;s done in ruby.</p>
<p>class Book<br />
  attr_accessor :title<br />
end</p>
<p>which gives you</p>
<p>book = Book.new<br />
book.title = &#8216;rftw&#8217;<br />
puts book.title # =&gt; &#8220;rftw&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1332</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Tue, 19 Aug 2008 13:43:50 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1332</guid>
		<description><![CDATA[Hi masklinn,

&gt; Don&#039;t use double underscore prefixes. Ever.
Changed. Thanks for the tip.

&gt; with Python 2.4 or more recent, you can use the &#039;property&#039; function 
Nice :)]]></description>
		<content:encoded><![CDATA[<p>Hi masklinn,</p>
<p>&gt; Don&#8217;t use double underscore prefixes. Ever.<br />
Changed. Thanks for the tip.</p>
<p>&gt; with Python 2.4 or more recent, you can use the &#8216;property&#8217; function<br />
Nice :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: masklinn</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1327</link>
		<dc:creator><![CDATA[masklinn]]></dc:creator>
		<pubDate>Tue, 19 Aug 2008 08:31:01 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1327</guid>
		<description><![CDATA[Another remark: with Python 2.4 or more recent, you can use the `property` function (because it&#039;s nothing more) as a decorator if you want e.g. to create a read-only property or make a member read-only:

&gt;&gt;&gt; class Foo(object):
....def __init__(self, some_value):
........self.some_value = some_value

		
&gt;&gt;&gt; foo = Foo(42)
&gt;&gt;&gt; foo.some_value
42
&gt;&gt;&gt; foo.some_value = 5
&gt;&gt;&gt; foo.some_value
5
&gt;&gt;&gt; class Foo(object):
....def __init__(self, some_value):
........self._some_value = some_value
....@property
....def some_value(self):
........return self._some_value

&gt;&gt;&gt; foo = Foo(42)
&gt;&gt;&gt; foo.some_value
42
&gt;&gt;&gt; foo.some_value = 5

Traceback (most recent call last):
..File &quot;&quot;, line 1, in 
....foo.some_value = 5
AttributeError: can&#039;t set attribute
&gt;&gt;&gt;]]></description>
		<content:encoded><![CDATA[<p>Another remark: with Python 2.4 or more recent, you can use the `property` function (because it&#8217;s nothing more) as a decorator if you want e.g. to create a read-only property or make a member read-only:</p>
<p>&gt;&gt;&gt; class Foo(object):<br />
&#8230;.def __init__(self, some_value):<br />
&#8230;&#8230;..self.some_value = some_value</p>
<p>&gt;&gt;&gt; foo = Foo(42)<br />
&gt;&gt;&gt; foo.some_value<br />
42<br />
&gt;&gt;&gt; foo.some_value = 5<br />
&gt;&gt;&gt; foo.some_value<br />
5<br />
&gt;&gt;&gt; class Foo(object):<br />
&#8230;.def __init__(self, some_value):<br />
&#8230;&#8230;..self._some_value = some_value<br />
&#8230;.@property<br />
&#8230;.def some_value(self):<br />
&#8230;&#8230;..return self._some_value</p>
<p>&gt;&gt;&gt; foo = Foo(42)<br />
&gt;&gt;&gt; foo.some_value<br />
42<br />
&gt;&gt;&gt; foo.some_value = 5</p>
<p>Traceback (most recent call last):<br />
..File &#8220;&#8221;, line 1, in<br />
&#8230;.foo.some_value = 5<br />
AttributeError: can&#8217;t set attribute<br />
&gt;&gt;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: masklinn</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1326</link>
		<dc:creator><![CDATA[masklinn]]></dc:creator>
		<pubDate>Tue, 19 Aug 2008 08:23:08 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1326</guid>
		<description><![CDATA[Remarks from a pythonista:

* Don&#039;t use double underscore prefixes. Ever. It&#039;s bad style. A single underscore is all you need, don&#039;t go for more, name mangling wasn&#039;t introduced to create pseudo-private members.

* While I realize it&#039;s for the sake of the example, don&#039;t create empty properties (the ones you&#039;ve created here) either, they create indirection and make the code slower and more complex for no gain. You can transparently introduce properties later if and when you need them.]]></description>
		<content:encoded><![CDATA[<p>Remarks from a pythonista:</p>
<p>* Don&#8217;t use double underscore prefixes. Ever. It&#8217;s bad style. A single underscore is all you need, don&#8217;t go for more, name mangling wasn&#8217;t introduced to create pseudo-private members.</p>
<p>* While I realize it&#8217;s for the sake of the example, don&#8217;t create empty properties (the ones you&#8217;ve created here) either, they create indirection and make the code slower and more complex for no gain. You can transparently introduce properties later if and when you need them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1322</link>
		<dc:creator><![CDATA[Robert]]></dc:creator>
		<pubDate>Mon, 18 Aug 2008 19:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1322</guid>
		<description><![CDATA[I use a technique using __call() instead of __get() and __set(). propertys are get and set using the convention used for functions like session_id(), where the function called with no args will return the current value, and the property can be set by calling with the new value, ie $object-&gt;property() returns, $object-&gt;property(&quot;new value&quot;) sets.

the __call() function checks against a list of available variables, so principles of data hiding can be adhered to where required. 

this method has the added advantage of being able to overwrite this default behaviour by adding in any other function, as in the requirement above of adding in a new filter/modifier on a property.

the __call() function can be seen at http://pastebin.com/f28429455. the code is ripped out of my current DataObject class and has some additional code to allow all objects to return the objects ID and load status.]]></description>
		<content:encoded><![CDATA[<p>I use a technique using __call() instead of __get() and __set(). propertys are get and set using the convention used for functions like session_id(), where the function called with no args will return the current value, and the property can be set by calling with the new value, ie $object-&gt;property() returns, $object-&gt;property(&#8220;new value&#8221;) sets.</p>
<p>the __call() function checks against a list of available variables, so principles of data hiding can be adhered to where required. </p>
<p>this method has the added advantage of being able to overwrite this default behaviour by adding in any other function, as in the requirement above of adding in a new filter/modifier on a property.</p>
<p>the __call() function can be seen at <a href="http://pastebin.com/f28429455" rel="nofollow">http://pastebin.com/f28429455</a>. the code is ripped out of my current DataObject class and has some additional code to allow all objects to return the objects ID and load status.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2008/08/17/no-need-for-setget-methods-in-python/#comment-1321</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Mon, 18 Aug 2008 12:27:20 +0000</pubDate>
		<guid isPermaLink="false">http://phpimpact.wordpress.com/?p=654#comment-1321</guid>
		<description><![CDATA[@Radoslav: Yes, that&#039;s a valid example. It&#039;s similar to the one I posted before. And that&#039;s exactly the point, to show how useful the property construct is.]]></description>
		<content:encoded><![CDATA[<p>@Radoslav: Yes, that&#8217;s a valid example. It&#8217;s similar to the one I posted before. And that&#8217;s exactly the point, to show how useful the property construct is.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

