<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UncleZeiv&#039;s Corner &#187; python</title>
	<atom:link href="http://unclezeiv.kerid.org/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://unclezeiv.kerid.org</link>
	<description>still in love with underscores</description>
	<lastBuildDate>Sun, 15 Jan 2012 22:30:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>About getters and setters in Python</title>
		<link>http://unclezeiv.kerid.org/2009/08/about-getters-and-setters-in-python?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=about-getters-and-setters-in-python</link>
		<comments>http://unclezeiv.kerid.org/2009/08/about-getters-and-setters-in-python#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:43:34 +0000</pubDate>
		<dc:creator>UncleZeiv</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[getters]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[pythonic]]></category>
		<category><![CDATA[setters]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://unclezeiv.kerid.org/?p=91</guid>
		<description><![CDATA[Recently I&#8217;ve been developing a fairly large Python application, involving a somewhat articulate and deep class hierarchy. With time, I ended up writing a certain amount of getters and setters which felt suspiciously unpythonic. Looking for better solutions I stumbled upon a number of sources making fun of people writing getters and setters in Python [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been developing a fairly large Python application, involving a somewhat articulate and deep class hierarchy. With time, I ended up writing a certain amount of getters and setters which felt suspiciously <em>unpythonic</em>. Looking for better solutions I stumbled upon a number of sources making fun of people writing getters and setters in Python (e.g. <a href="http://dirtsimple.org/2004/12/python-is-not-java.html" target="_blank">Python Is Not Java</a>), because:</p>
<ul>
<li>there&#8217;s <strong>no real data member protection</strong> in Python anyway (&#8220;we are all consenting adults here&#8221;)</li>
<li>if you later want to embed some logic in the retrieval of an attribute, <strong>you can keep the same interface</strong> by just adding a <a href="http://docs.python.org/library/functions.html#property" target="_blank">property</a></li>
</ul>
<p>These arguments were so compelling that made me feel pretty stupid. Consequently, I immediately started converting all my getters and setters into variables or, when needed, into properties.</p>
<p>Unfortunately, it soon became apparent that I had not considered all the facets of the problem. Problems surfaced soon, primarily because, as I had to find out the hard way, <strong>avoiding getters/setters does not play <em>that</em> well with inheritance</strong>.</p>
<p>First of all, overriding the access of an attribute becomes a bit quirky &#8212; despite being perfectly acceptable when using getters. In particular, the child class must know if a certain attribute is indeed an attribute or a property &#8212; and this already breaks the promise of keeping the switch from variable to property a local change.</p>
<div class="codecolorer-container python default codecolorer-noborder" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Foo<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span><span style="color: #008000;">property</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">5</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> Bar<span style="color: black;">&#40;</span>Foo<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span><span style="color: #008000;">property</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> Foo.<span style="color: black;">foo</span>.<span style="color: black;">fget</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">1</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> Foo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">foo</span> <span style="color: #808080; font-style: italic;"># 5</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> Bar<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">foo</span> <span style="color: #808080; font-style: italic;"># 6</span></div></td></tr></tbody></table></div>
<p>The syntax gets really cumbersome. For instance, if you want to override only the getter <em>or</em> the setter, verbosity ensues:</p>
<div class="codecolorer-container python default codecolorer-noborder" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> Foo<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span><span style="color: #008000;">property</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">5</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span>foo.<span style="color: black;">setter</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> val<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> val<br />
<br />
<span style="color: #808080; font-style: italic;"># one way to do that</span><br />
<span style="color: #ff7700;font-weight:bold;">class</span> Bar1<span style="color: black;">&#40;</span>Foo<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span><span style="color: #008000;">property</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> Foo.<span style="color: black;">foo</span>.<span style="color: black;">fget</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">1</span><br />
<br />
&nbsp; &nbsp; <span style="color: #66cc66;">@</span>foo.<span style="color: black;">setter</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> val<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> Foo.<span style="color: black;">foo</span>.<span style="color: black;">fset</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> val<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># another way</span><br />
<span style="color: #ff7700;font-weight:bold;">class</span> Bar2<span style="color: black;">&#40;</span>Foo<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo_get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> Foo.<span style="color: black;">foo</span>.<span style="color: black;">fget</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">1</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> foo_set<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> val<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> Foo.<span style="color: black;">foo</span>.<span style="color: black;">fset</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> val<span style="color: black;">&#41;</span><br />
<br />
&nbsp; &nbsp; foo <span style="color: #66cc66;">=</span> <span style="color: #008000;">property</span><span style="color: black;">&#40;</span>foo_get<span style="color: #66cc66;">,</span> foo_set<span style="color: black;">&#41;</span><br />
<br />
Foo<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">foo</span> <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">4</span><br />
Bar1<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">foo</span> <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">3</span><br />
Bar2<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">foo</span> <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">2</span></div></td></tr></tbody></table></div>
<p>Granted, true Pythoners would say that this is not Python&#8217;s fault but mine, as I have evidently made some wrong, or at least unpythonic, design decisions at a higher level. That&#8217;s an acceptable criticism, but I still think that the organization of my program was fair when employing getters and setters. Most importantly, though, the consequences of substituting them in class hierarchies where overriding is common have not been sufficiently explained by the previously mentioned Internet sources.</p>
<p>In other words, sometimes &#8220;<em><a href="http://www.python.org/dev/peps/pep-0020/">practicality beats purity</a></em>&#8220;!</p>
]]></content:encoded>
			<wfw:commentRss>http://unclezeiv.kerid.org/2009/08/about-getters-and-setters-in-python/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Egocentric pumpkin</title>
		<link>http://unclezeiv.kerid.org/2008/10/egocentric-pumpkin?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=egocentric-pumpkin</link>
		<comments>http://unclezeiv.kerid.org/2008/10/egocentric-pumpkin#comments</comments>
		<pubDate>Fri, 31 Oct 2008 00:34:32 +0000</pubDate>
		<dc:creator>UncleZeiv</dc:creator>
				<category><![CDATA[Blender]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[blend]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://unclezeiv.kerid.org/?p=68</guid>
		<description><![CDATA[I&#8217;m back from the Blender Conference, which was very stimulating as always. For some reason, it&#8217;s very easy to hang out with the other participants, and to relate with people you&#8217;ve never heard of as if they were close friends! My opinion is that Blender hits a soft spot between technical and artistic interests (and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back from the <a href="http://unclezeiv.kerid.org/2008/10/leaving-for-blender-conference" target="_blank">Blender Conference</a>, which was very stimulating as always. For some reason, it&#8217;s very easy to hang out with the other participants, and to relate with people you&#8217;ve never heard of as if they were close friends! My opinion is that Blender hits a soft spot between technical and artistic interests (and possibly even ethical, because of the open source part): this makes the overall atmosphere one of&#8230; <strong>tasteful nerdiness</strong> I would say <img src='http://unclezeiv.kerid.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>By the way let me stress once again how <strong>kind and helpful</strong> are all the top Blender heads, despite their success in the field. @ndy and Bassam are always in for a chat, and Brecht is always painstakingly giving guidance to hordes of famelic developers fighting their way through Blender&#8217;s codebase (I was one of them by the way!).</p>
<p>Anyway. It suddenly occurred to me that since my <a href="http://unclezeiv.kerid.org/2008/04/summer-is-starting-now" target="_blank">initial involvement</a> in the Summer of Code, I have almost completely stopped <em>using</em> Blender, apart from setting up test scenes.</p>
<p>This is why today I took the time to carry out <strong>a small Halloween-themed project</strong>. Actually, I don&#8217;t care at all about Halloween, but <strong>anthropomorphic pumpkins</strong> are undeniably a fun subject.</p>
<div id="attachment_69" class="wp-caption aligncenter" style="width: 410px"><a href="http://unclezeiv.kerid.org/download/2008/10/versione3.png"><img class="size-medium wp-image-69" title="Egocentric pumpkin" src="http://unclezeiv.kerid.org/download/2008/10/versione3-400x300.png" alt="Egocentric pumpkin" width="400" height="300" /></a><p class="wp-caption-text">Egocentric pumpkin</p></div>
<p>The project eventually turned out to be mostly a programming effort after all. The blend file contains two scenes:</p>
<ul>
<li>the pumpkin scene, where a Python <em>script link</em> takes care to move the camera and the eyes of the pumpkin randomly at each frame, also setting random values for a couple of shape keys and changing the color of the background</li>
<li>the &#8220;Polaroids&#8221; scene, where a number of randomly rotated objects display the frames rendered in the other scene (all assignments were carried out through Python scripting again)</li>
</ul>
<p>The artistic quality of the result is <strong>pretty questionable</strong>, but, hey, if someone wants to improve shading, modeling, or whatever, here is the <a href="http://unclezeiv.kerid.org/download/2008/10/halloweenblend.zip">halloween.blend</a> blend file to play with.</p>
<div id="attachment_70" class="wp-caption aligncenter" style="width: 410px"><a href="http://unclezeiv.kerid.org/download/2008/10/versione2.png"><img class="size-medium wp-image-70" title="Egocentric pumpkin (monocolor)" src="http://unclezeiv.kerid.org/download/2008/10/versione2-400x300.png" alt="Egocentric pumpkin (monocolor)" width="400" height="300" /></a><p class="wp-caption-text">Egocentric pumpkin (monocolor)</p></div>
]]></content:encoded>
			<wfw:commentRss>http://unclezeiv.kerid.org/2008/10/egocentric-pumpkin/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

