<?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>t+1 &#187; clepy</title>
	<atom:link href="http://blog.tplus1.com/index.php/category/clepy/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tplus1.com</link>
	<description>Programming, gardening, economics, life in Cleveland Heights</description>
	<lastBuildDate>Tue, 24 Aug 2010 00:16:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I learned some neat stuff at clepy last night</title>
		<link>http://blog.tplus1.com/index.php/2008/11/04/i-learned-some-neat-stuff-at-clepy-last-night/</link>
		<comments>http://blog.tplus1.com/index.php/2008/11/04/i-learned-some-neat-stuff-at-clepy-last-night/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 20:37:40 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Cleveland Life]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[clepy]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/?p=245</guid>
		<description><![CDATA[Brian Beck showed how to use metaclasses and descriptors to make DSLs with python.
I do this kind of this kind of thing every so often in my code:

def f(x):
&#160;&#160;&#160;&#160;class C(object):
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;y = x
&#160;&#160;&#160;&#160;return C

That function takes a parameter and makes and returns a class based on that parameter.  Whoop-di-do.  I was surprised to learn [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.brianbeck.com">Brian Beck</a> showed how to use metaclasses and descriptors to make DSLs with python.</p>
<p>I do this kind of this kind of thing every so often in my code:<br />
<pre><code>
def f(x):
&nbsp;&nbsp;&nbsp;&nbsp;class C(object):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y = x
&nbsp;&nbsp;&nbsp;&nbsp;return C
</code></pre></p>
<p>That function takes a parameter and makes and returns a class based on that parameter.  Whoop-di-do.  I was surprised to learn that you can&#8217;t do this:<br />
<pre><code>
class C(object):
&nbsp;&nbsp;&nbsp;&nbsp;x = 99
&nbsp;&nbsp;&nbsp;&nbsp;class D(object):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y = x + 1
</code></pre></p>
<p>I gotta explore this some more until it makes sense.</p>
<p>Here&#8217;s another neat trick:  It isn&#8217;t possible to add two classes together:<br />
<pre><code>
&gt;&gt;&gt; class C(object):
...&nbsp;&nbsp;&nbsp;&nbsp; pass
...
&gt;&gt;&gt; C + C
------------------------------------------------------------
Traceback (most recent call last):
&nbsp;&nbsp;File &quot;&lt;ipython console&gt;&quot;, line 1, in &lt;module&gt;
TypeError: unsupported operand type(s) for +: &#039;type&#039; and &#039;type&#039;
</code></pre></p>
<p>But if you want to support this, the solution would be to define an __add__ method on the metaclass:<br />
<pre><code>
&gt;&gt;&gt; type(C)
&lt;type &#039;type&#039;&gt;
&gt;&gt;&gt; class MC(type):
...&nbsp;&nbsp;&nbsp;&nbsp; def __add__(self, other):
...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &#039;Adding!&#039;
...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 99
... 
&gt;&gt;&gt; class C(object):
...&nbsp;&nbsp;&nbsp;&nbsp; __metaclass__ = MC
... 
&gt;&gt;&gt; C + C
Adding!
99
</code></pre></p>
<p>Wacky, right?  More realistically, I could build a new class by taking attributes of both classes together.  In other words, if class C has a class attribute x, and class D has a class attribute y, then we can use a metaclass to add C and D together to get a new class E, that has both x and y as class attributes.</p>
<p>In this example, C has a class attribute x and D has a class attribute y.  When I add the two classes, I get a new class with both of those class attributes.<br />
<pre><code>
&gt;&gt;&gt; C.x, D.y
(99, 98)
&gt;&gt;&gt; E = C + D
&gt;&gt;&gt; E.x, E.y
(99, 98)
</code></pre></p>
<p>Here&#8217;s the metaclass that allows this sort of nonsense:<br />
<pre><code>
class MC(type):

&nbsp;&nbsp;&nbsp;&nbsp;def __add__(self, other):

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;class E(self):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pass

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for k,v in other.__dict__.items():
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if k not in (&#039;__dict__&#039;, ):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setattr(E, k, v)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return E
</code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2008/11/04/i-learned-some-neat-stuff-at-clepy-last-night/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Google presentation at Clepy on August 6th, 2007</title>
		<link>http://blog.tplus1.com/index.php/2007/08/06/google-presentation-at-clepy-on-august-6th-2007/</link>
		<comments>http://blog.tplus1.com/index.php/2007/08/06/google-presentation-at-clepy-on-august-6th-2007/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 01:43:33 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[clepy]]></category>

		<guid isPermaLink="false">http://blog.tplus1.com/index.php/2007/08/06/google-presentation-at-clepy-on-august-6th-2007/</guid>
		<description><![CDATA[Tonight Brian Fitzpatrick (Fitz) from the Chicago Google office did a presentation for the clepy group on version control at Google.  They use subversion on top of their own super-cool bigtable filesystem back end.
We had a good discussion on the merits of centralized vs. decentralized version control.  According to Fitz, decentralized systems discourage [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight Brian Fitzpatrick (Fitz) from the Chicago Google office did a presentation for the <a href="http://clepy.org">clepy</a> group on version control at Google.  They use subversion on top of their own super-cool bigtable filesystem back end.</p>
<p>We had a good discussion on the merits of centralized vs. decentralized version control.  According to Fitz, decentralized systems discourage collaboration.  He made the joke, &#8220;Did you hear about the decentralized version control conference?  Nobody showed up.&#8221; He made the point that centralized repositories encourage review and discussion.  I agree with that.</p>
<p>Apparently subversion 1.5, which will be released in a few months, will have much improved merging facilities.  We won&#8217;t need to use <code>--stop-on-copy</code> to figure out where we branched. Also, it will be safe to repeat a merge, because nothing will happen on the second attempt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tplus1.com/index.php/2007/08/06/google-presentation-at-clepy-on-august-6th-2007/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
