<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<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/"
	>

<channel>
	<title>Adam Byrtek</title>
	<link>http://www.adambyrtek.net</link>
	<description>Sceptical Point of View</description>
	<pubDate>Thu, 24 Apr 2008 22:22:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Gone sailing</title>
		<link>http://www.adambyrtek.net/2008/04/24/gone-sailing/</link>
		<comments>http://www.adambyrtek.net/2008/04/24/gone-sailing/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 22:14:32 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[personal]]></category>

		<category><![CDATA[sailing]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/04/24/gone-sailing/</guid>
		<description><![CDATA[It&#8217;s time to unplug for some time and calm down, disconnect not only from the Web, but also from the daily life. In case you need me during the coming week, I&#8217;ll be sailing along the Spanish coast &#8212; no mobile nor WiFi coverage, sorry. I have several drafts of blog posts waiting patiently to [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Gone sailing", url: "http://www.adambyrtek.net/2008/04/24/gone-sailing/" });</script>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to unplug for some time and calm down, disconnect not only from the Web, but also from the daily life. In case you need me during the coming week, I&#8217;ll be sailing along the Spanish coast &#8212; no mobile nor WiFi coverage, sorry. I have several drafts of blog posts waiting patiently to be polished, so be prepared for something new when I return with my mental batteries reloaded.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Gone+sailing&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F04%2F24%2Fgone-sailing%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/04/24/gone-sailing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why it&#8217;s good to be lazy</title>
		<link>http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/</link>
		<comments>http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 00:45:02 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[functional programming]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[slides]]></category>

		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/</guid>
		<description><![CDATA[Recently I&#8217;ve presented my talk on Functional Programming with Python at the RuPy conference in Poznań, the slides (this time in English) are available below. Organizers promise that video recordings from all talks will be published shortly, I will keep you informed when it happens.




<script type="text/javascript">SHARETHIS.addEntry({ title: "Why it&#8217;s good to be lazy", url: "http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve presented my talk on <em>Functional Programming with Python</em> at the <a href="http://rupy.eu/">RuPy conference</a> in Poznań, the slides (this time in English) are available below. Organizers promise that video recordings from all talks will be published shortly, I will keep you informed when it happens.</p>
<p><center><object style="margin:0px" width="425" height="355">
<param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=functionalpython-1208997222437657-8"/>
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=functionalpython-1208997222437657-8" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></center></p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Why+it%26%238217%3Bs+good+to+be+lazy&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F04%2F24%2Fwhy-its-good-to-be-lazy%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tracing and profiling Ruby code</title>
		<link>http://www.adambyrtek.net/2008/03/12/tracing-and-profiling-ruby-code/</link>
		<comments>http://www.adambyrtek.net/2008/03/12/tracing-and-profiling-ruby-code/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 23:09:22 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[aop]]></category>

		<category><![CDATA[profilling]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/03/12/tracing-and-profiling-ruby-code/</guid>
		<description><![CDATA[Every child knows that premature optimization is the root of all evil, and even when optimization is necessary, we should concentrate on the bottlenecks. This is where profiling becomes crucial. Ruby includes a simple profiler in the standard library, so to generate a report of program execution you just have to invoke it with ruby [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Tracing and profiling Ruby code", url: "http://www.adambyrtek.net/2008/03/12/tracing-and-profiling-ruby-code/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Every child knows that premature optimization is the root of all evil, and even when optimization is necessary, we should concentrate on the bottlenecks. This is where <a href="http://en.wikipedia.org/wiki/Performance_analysis">profiling</a> becomes crucial. Ruby includes a simple profiler in the standard library, so to generate a report of program execution you just have to invoke it with <code>ruby -r profile</code> or add <code>require "profile"</code> to the code. In fact the whole profiler is implemented in only 59 lines of Ruby and relies on <code>set_trace_func</code> method to register a callback tracing certain events during program execution (method calls and returns in this case). This tool should suffice for simple profiling, but if you need something faster and more powerful you should rather try <a href="http://ruby-prof.rubyforge.org/">ruby-prof</a>.</p>
<p>The powerful introspection features of dynamic languages make tricks like this not only possible, but also straightforward. This gives me an idea that the same approach could be used to implement an aspect-oriented library for Ruby &#8212; but I&#8217;m almost sure somebody has already tried this.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Tracing+and+profiling+Ruby+code&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F03%2F12%2Ftracing-and-profiling-ruby-code%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/03/12/tracing-and-profiling-ruby-code/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Thinner Ruby deployment</title>
		<link>http://www.adambyrtek.net/2008/03/10/thinner-ruby-deployment/</link>
		<comments>http://www.adambyrtek.net/2008/03/10/thinner-ruby-deployment/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 19:07:23 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[deployment]]></category>

		<category><![CDATA[http]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/03/10/thinner-ruby-deployment/</guid>
		<description><![CDATA[In the post on benchmarking HTTP performance I mentioned that according to my tests a cluster of Mongrels performs about 10-20% worse than the same number of FastCGI processes behind a reverse proxy. Recently I tried Thin, a new web server based on Mongrel libraries, and it turns out to be a solution that gets [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Thinner Ruby deployment", url: "http://www.adambyrtek.net/2008/03/10/thinner-ruby-deployment/" });</script>]]></description>
			<content:encoded><![CDATA[<p>In the post on <a href="http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/">benchmarking HTTP performance</a> I mentioned that according to my tests a cluster of Mongrels performs about 10-20% worse than the same number of FastCGI processes behind a reverse proxy. Recently I tried <a href="http://code.macournoyer.com/thin/">Thin</a>, a new web server based on Mongrel libraries, and it turns out to be a solution that gets the best of both worlds. It is very easy to setup and manage (even easier than Mongrel), extremely flexible (mostly thanks to <a href="http://rack.rubyforge.org/">Rack</a>) and really fast. It matches FastCGI in performance, without all the quirks, and can communicate through UNIX sockets too. I have to admit that I was impressed by the simple and clean design of Thin (which is based on existing quality modules). The only disadvantage is that it isn&#8217;t very mature yet &#8212; but in the near future Thin might become the best server for deploying Ruby web applications.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Thinner+Ruby+deployment&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F03%2F10%2Fthinner-ruby-deployment%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/03/10/thinner-ruby-deployment/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Benchmarking HTTP performance</title>
		<link>http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/</link>
		<comments>http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 21:48:51 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[benchmark]]></category>

		<category><![CDATA[deployment]]></category>

		<category><![CDATA[http]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/</guid>
		<description><![CDATA[Deployment of Rails application is a subject that tends to raise some hot discussions, leading to many misunderstandings. That&#8217;s why I decided to try different deployment strategies and check for myself how they perform.
To make any reasonable comparisons it is crucial to measure performance of different configurations. The most common metric is the number of [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Benchmarking HTTP performance", url: "http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Deployment of Rails application is a subject that tends to raise some hot discussions, leading to many misunderstandings. That&#8217;s why I decided to try different deployment strategies and check for myself how they perform.</p>
<p>To make any reasonable comparisons it is crucial to measure performance of different configurations. The most common metric is the number of requests processed per second (RPS). This metric (and many others) can be measured by HTTP benchmarking tools like <code>ab</code> and <code>httperf</code>.</p>
<p>The first tool, <code>ab</code>, comes bundled with Apache and is very easy to use, so it is a good option to start with. You can provide a total number of requests to perform (<code>-n</code>) and a number of concurrent requests (<code>-c</code>). If you like you can also give maximum time to wait for a response (<code>-t</code>), as real users won&#8217;t wait for a page to load more than just a few seconds.</p>
<p>For example to issue 1000 requests with concurrency of 100 you might run (remember about a trailing slash in the URL, it is necessary)</p>
<pre>
% ab -n 1000 -c 100 http://www.example.com/
</pre>
<p><code>httperf</code> is a slightly more complex tool with more features. The most important is a possibility to issue multiple request per connection (<code>--num-calls</code> command line option) and support for replaying sessions that imitate real use cases. The tool is also believed to be more robust and give more reliable results. The basic use might look like</p>
<pre>
% httperf --server www.example.com --num-conn 1000 \
          --num-call 10 --rate 10
</pre>
<p>This will issue 1000 connections with a rate of ten connections per second (and no more), passing ten requests through each connection before it is closed. So the total number of requests will be 10000. Be sure to remember the distinction between connections and requests, otherwise this can lead to confusion when interpreting results. Another tricky part is the actual meaning of the <code>rate</code> command line option. Rate is not a number of simultaneous connections at a given time (like concurrency in <code>ab</code>), but rather a number of new connections made per second. This means your RPS cannot exceed rate given multiplied by number of requests per connection. So <code>httperf</code> has to be ran multiple times with increasing rate to find the saturation point of the server.<sup><a href="#note1">[1]</a></sup></p>
<p>When benchmarking HTTP performance don&#8217;t just accept the first results blindly. Think for a minute what you are actually measuring. Check the status of the replies &mdash; if most of requests fail it is a sign that something is wrong, if you are getting 3xx redirects probably you should rather test the URL the redirects point to. If many requests have timed out the concurrency you requested might be too high.</p>
<p>Never perform such tests from your desktop machine far away from the server. In the perfect world you should run the benchmark from an independent machine in the same network segment as the server, and make sure the network is not saturated during the test. If you have to run the tests on local machine, remember that the load caused by the test itself can skew the results (note that from my experience <code>ab</code> causes considerably smaller load than <code>httperf</code>).</p>
<p>Finally consider where the URL you provided points to. If this is a static page or file, you can easily achieve thousands of RPS, as the performance is bounded mostly by disk operations. On the other hand if you measure a dynamic page running multiple SQL queries you might get very low results, as the database will be the bottleneck. Many recommend to benchmark a simple dynamic &#8220;hello world&#8221; application that doesn&#8217;t communicate with the database. But if you want to measure performance of the application, not a web server, you can measure and compare different URLs.</p>
<p>In my benchmarks I found out that three Mongrel instances load-balanced by Pound are about 10-20% slower than three static<sup><a href="#note2">[2]</a></sup> FastCGI processed running from a vanilla Apache installation. It is probably due to the fact that the front-end server communicates with Mongrels through TCP connections, which are considerably slower than UNIX sockets used by FastCGI. On the other hand this architecture makes scaling Mongrels easier, because one load balancer can proxy requests to multiple machines.</p>
<p>It looks like there are reasonable arguments for both strategies, and I find it a bit surprising that the whole Rails community is voting against FastCGI, calling it a legacy solution. It&#8217;s true that FastCGI can be tricky to setup correctly &#8212; but at the end of the day it performs better, and there are other benchmarks showing <a href="http://blog.kovyrin.net/2006/08/28/ruby-performance-results/lang/en/">similar results</a> (as shown on <a href="http://blog.kovyrin.net/wp-content/uploads/2006/08/ruby-tests-diag.gif">this chart</a>).</p>
<p>&#8212;</p>
<p><a name="note1"></a><sup>[1]</sup> More information on good HTTP benchmarking practices and the usage of <code>httperf</code> can be found in the <a href="http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/">Linux HTTP Benchmarking HOWTO</a>.</p>
<p><a name="note2"></a><sup>[2]</sup> Never use dynamic FastCGI processes for production purposes. Dynamic processes are killed when unused and due to timing issues users can get internal server errors. Moreover every request assigned to a fresh process is delayed, as it has to wait for the new process to boot.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Benchmarking+HTTP+performance&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F03%2F05%2Fbenchmarking-http-performance%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/03/05/benchmarking-http-performance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Subversion Scripts for Finder</title>
		<link>http://www.adambyrtek.net/2008/02/24/subversion-scripts-for-finder/</link>
		<comments>http://www.adambyrtek.net/2008/02/24/subversion-scripts-for-finder/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 21:43:02 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[applescript]]></category>

		<category><![CDATA[macosx]]></category>

		<category><![CDATA[projects]]></category>

		<category><![CDATA[scm]]></category>

		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/02/24/subversion-scripts-for-finder/</guid>
		<description><![CDATA[Subversion is one of the basic tools in my daily work. I know, distributed version control is more en vogue those days, but I would argue that for personal use and small teams Subversion is still a reasonable choice[1] &#8212; it is very popular, flexible and there are many additional tools available.
About a year ago, [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Subversion Scripts for Finder", url: "http://www.adambyrtek.net/2008/02/24/subversion-scripts-for-finder/" });</script>]]></description>
			<content:encoded><![CDATA[<p><a href="http://subversion.tigris.org/">Subversion</a> is one of the basic tools in my daily work. I know, distributed version control is more <em>en vogue</em> those days, but I would argue that for personal use and small teams Subversion is still a reasonable choice<sup><a href="#note1">[1]</a></sup> &#8212; it is very popular, flexible and there are many additional tools available.</p>
<p>About a year ago, when I started to play with my first Mac, I was looking for Subversion tools that can integrate smoothly with Finder &#8212; the standard Mac OS X file manager. To my surprise I couldn&#8217;t find anything useful, only <a href="http://scplugin.tigris.org/">SCPlugin</a> which didn&#8217;t work at that time, and as far as I know is still somehow buggy. So I decided to write my own set of scripts, as an excuse to play with AppleScript &#8212; a funny high-level scripting language that can speak with Mac applications (including Finder) over simple interfaces called <em>dictionaries</em>, not surprisingly consisting of nouns (objects) and verbs (methods). This custom set of scripts had been so useful to me (especially when invoked from Quicksilver) that I decided to release it publicly, starting a small open source project.</p>
<p>Recently I&#8217;ve released version 1.2 of the scripts, including support for Copy, Move and Checkout operations, with improved Leopard and MacPorts support. The release was also a good excuse to make some adjustments to <a href="http://svn-finder.sourceforge.net/">the project page</a> and publish <a href="http://svn-finder.sourceforge.net/screencast-usage.html">a screencast</a> showing how to use the scripts. Judging from the download statistics and the feedback I get, people find the project useful, so if you are a Mac user consider <a href="http://svn-finder.sourceforge.net/">giving it a try</a>!</p>
<p>&#8212;</p>
<p><a name="note1"></a><sup>[1]</sup> But not for projects with many independent branches of development &#8212; branching and merging sucks in Subversion (it will be improved in Subversion 1.5, which is now in beta). Linus&#8217; critical opinion on Subversion is well known, and I don&#8217;t claim it is the best choice for large open source projects (though many such projects use it).</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Subversion+Scripts+for+Finder&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F02%2F24%2Fsubversion-scripts-for-finder%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/02/24/subversion-scripts-for-finder/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trivial accessors and uniform access</title>
		<link>http://www.adambyrtek.net/2008/02/09/trivial-accessors-and-uniform-access/</link>
		<comments>http://www.adambyrtek.net/2008/02/09/trivial-accessors-and-uniform-access/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 17:04:07 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[oop]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/02/09/trivial-accessors-and-uniform-access/</guid>
		<description><![CDATA[Some tend to think that Java is a synonym of object orientation done right, some even don&#8217;t know other alternatives. But it was always unnatural to me that most of Java classes start their existence with plenty of boilerplate code like this[1]

public class Money &#123;
    private double amount;
&#160;
    public [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Trivial accessors and uniform access", url: "http://www.adambyrtek.net/2008/02/09/trivial-accessors-and-uniform-access/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Some tend to think that Java is a synonym of object orientation done right, some even don&#8217;t know other alternatives. But it was always unnatural to me that most of Java classes start their existence with plenty of boilerplate code like this<sup><a href="#note1">[1]</a></sup></p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Money <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">double</span> amount;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">double</span> getAmount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">amount</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setAmount<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">double</span> amount<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">amount</span> = amount;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>This is a lot of code to write just to define one single property, a code that is mostly meaningless. But in Java you have to introduce getters and setters from the very beginning, or it will bite you back in the future. It clearly contradicts with the <a title="Don't Repeat Yourself">DRY</a> principle and a preference for evolutionary design, which discourages writing code that is useless right now, but may (or may not) be needed in the future. Things get even worse when such code is created automatically by some code generation tool.</p>
<p>In theory your methods should always have some meaningful behaviour, and your should <a href="http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html">avoid trivial accessors</a> in the public interface. This is a good rule of a thumb, and when it&#8217;s broken, this is often a symptom of some wrong design decisions. Though in many practical situations you simply need trivial accessors without any behaviour, for example when mapping relational databases to objects<sup><a href="#note2">[2]</a></sup>.</p>
<p>The whole problem boils down to the fact that in Java you can&#8217;t apply the <a href="http://en.wikipedia.org/wiki/Uniform_access_principle"><em>Uniform Access Principle</em></a>, which states that users of a class shouldn&#8217;t care whether a given service is implemented through storage (property) or computation (method). But the syntax for accessing a property and calling a method in Java is completely different, and you can&#8217;t start with a simple public property and change it into a method later when it becomes necessary, keeping the public interface intact. So you are told not to use public properties at all and always define trivial accessors <q>just in case</q>.</p>
<p>I would like to contrast this approach with two dynamic languages, Python and Ruby, each presenting a different point of view on the problem we discuss.</p>
<p>In Ruby — which has been inspired by Smalltalk — properties (instance variables) are always private, and the only way to interact with an object is by sending <em>messages</em> to it. This is similar to a method call, but the meaning is slightly different, and there are certain conventions to make the syntax nicer. You can&#8217;t access instance variables outside the class, so the following code</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">cash = Money.<span style="color:#9900CC;">new</span>
cash.<span style="color:#9900CC;">amount</span> = <span style="color:#006666;">10</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> cash.<span style="color:#9900CC;">amount</span></pre></div></div>

<p>is actually the same as sending messages <code>amount=</code> and <code>amount</code> to the instance, which can be written explicitly as</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">cash = Money.<span style="color:#9900CC;">new</span>
cash.<span style="color:#9900CC;">amount</span>=<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> cash.<span style="color:#9900CC;">amount</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This means that Ruby has an uniform syntax for attribute access, but you still have to write message handling methods inside the class. This is where <code>attr_accessor</code> comes in handy (along with its siblings <code>attr_reader</code> and <code>attr_writer</code>), avoiding duplication and making the code more terse. The following piece of code</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Money
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:amount</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>has the same effect as</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Money
  <span style="color:#9966CC; font-weight:bold;">def</span> amount
    <span style="color:#0066ff; font-weight:bold;">@amount</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> amount=<span style="color:#006600; font-weight:bold;">&#40;</span>value<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@amount</span> = value
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>When the class evolves and we would like to make accessors more complex (for example implement lazy load or caching) we can replace <code>attr_accessor</code> with real methods, keeping external interface intact.</p>
<p>Python takes a different approach than the message passing metaphor. It publicly exposes all attributes of an instance as <em>slots</em> you can access freely. Inside such slot can be any object (in Pythonic sense of the word), including standard objects (integers, tuples, etc.) and methods. The client simply fetches object from the slot and either invokes it (if it is a callable) or uses its value directly — so the access is not uniform.</p>
<p>To maintain an illusion of uniform access when refactoring a property into a method you can use the <code>property()</code> function, passing new getters and setters as arguments. This means you can start with a class as simple as</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">class</span> Money<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">amount</span> = <span style="color: #ff4500;">0</span></pre></div></div>

<p>Later, when you need some more complex accessors, you can refactor the class with <code>property()</code>, maintaining the same external interface</p>

<div class="wp_syntax"><div class="code"><pre class="python"><span style="color: #ff7700;font-weight:bold;">class</span> Money<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> _get_amount<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Getter code here</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">amount</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> _set_amount<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, value<span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Setter code here</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">amount</span> = value
&nbsp;
    amount = <span style="color: #008000;">property</span><span style="color: black;">&#40;</span>_get_amount, _set_amount<span style="color: black;">&#41;</span></pre></div></div>

<p>As you see the code is not as clear as with Ruby, and there are some other problems with this approach, but it is possible to maintain uniform access in Python.</p>
<p>I believe obeying the Uniform Access Principle is the right way of solving the accessor problem, and both Ruby and Python handle this quite well. If you see trivial <code>getProperty()</code> and <code>setProperty()</code> methods in Python or Ruby code, stay aware. This probably means the code has been written by a programmer who is unable to change his mindset.</p>
<p>&#8212;</p>
<p><a name="note1"></a><sup>[1]</sup> To convince you this is not a fake example I did a quick search on the Web, finding <a href="http://cs.nyu.edu/courses/spring03/V22.0474-001/lectures/junit/Money.java">this piece of code</a>.</p>
<p><a name="note2"></a><sup>[2]</sup> Martin Fowler on page 155 of his <a title="Patterns of Enterprise Application Architecture">PEAA</a> book gives example of a class to map a simple person table. He writes <q>it starts with data fields and accessors</q> and then gives an example of over twenty lines of boilerplate accessor code.</p>
<p>PS. Thanks to Tomek for reviewing the first draft of this article.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Trivial+accessors+and+uniform+access&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F02%2F09%2Ftrivial-accessors-and-uniform-access%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/02/09/trivial-accessors-and-uniform-access/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sharing knowledge inside a team</title>
		<link>http://www.adambyrtek.net/2008/02/04/sharing-knowledge-inside-a-team/</link>
		<comments>http://www.adambyrtek.net/2008/02/04/sharing-knowledge-inside-a-team/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 20:33:06 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[agile]]></category>

		<category><![CDATA[code sprinters]]></category>

		<category><![CDATA[education]]></category>

		<category><![CDATA[gtd]]></category>

		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/02/04/sharing-knowledge-inside-a-team/</guid>
		<description><![CDATA[What I like about being a programmer is that you have to constantly learn new things — either new languages, tools and frameworks that make your job easier (and more fun), or interesting theoretical concepts that stretch your mind, a kind of mental yoga. Being a math graduate I can tell that even if this [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Sharing knowledge inside a team", url: "http://www.adambyrtek.net/2008/02/04/sharing-knowledge-inside-a-team/" });</script>]]></description>
			<content:encoded><![CDATA[<p>What I like about being a programmer is that you have to constantly learn new things — either new languages, tools and frameworks that make your job easier (and more fun), or interesting theoretical concepts that stretch your mind, a kind of mental yoga. Being a math graduate I can tell that even if this knowledge is not instantly useful, it will probably pay off in the future.</p>
<p>There are different ways for programmers to gather knowledge, most have something to do with reading. But, as skilled craftsmen have known for centuries, the best way to learn is from a person who is willing to share his real-life experiences, tricks and habits. For example skimming through a cryptic Vim reference sheet or reading even the best tutorial is so much different than seeing the actual usage patterns of a skilled user.</p>
<p>That&#8217;s why every week at <a href="http://www.codesprinters.com">Code Sprinters</a> we organize <em>Tech Talks</em>, meetings during which one person speaks about about a topic of his (or her) interest. Those are not official presentations with slides, but rather discussions around the whiteboard, sometimes turning into hands-on workshop. The subject doesn&#8217;t have to be purely technical &#8212; a few weeks ago I spoke about <a href="http://en.wikipedia.org/wiki/Getting_Things_Done">Getting Things Done</a>, a way to organize myself I use and find very useful. We don&#8217;t claim that we are experts on a given subject, but certainly each of us knows something that might be interesting to others.</p>
<p>I think holding such meetings is a great (and quite easy) way to spread the knowledge inside a team or a small company, and it&#8217;s also fun!</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Sharing+knowledge+inside+a+team&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F02%2F04%2Fsharing-knowledge-inside-a-team%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/02/04/sharing-knowledge-inside-a-team/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Functional programming in Python</title>
		<link>http://www.adambyrtek.net/2008/01/30/functional-programming-in-python/</link>
		<comments>http://www.adambyrtek.net/2008/01/30/functional-programming-in-python/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 12:45:18 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[functional programming]]></category>

		<category><![CDATA[krakow]]></category>

		<category><![CDATA[math]]></category>

		<category><![CDATA[polish]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[slides]]></category>

		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/01/30/functional-programming-in-python/</guid>
		<description><![CDATA[Below you can find the slides from my talk on functional programming in Python, which I presented a few days ago at the first meeting of Pythonistas in Kraków (the slides are in Polish only, sorry). Feel free to leave your comments!




Update 2008-04-24: Slides are also available in English.
<script type="text/javascript">SHARETHIS.addEntry({ title: "Functional programming in Python", url: "http://www.adambyrtek.net/2008/01/30/functional-programming-in-python/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Below you can find the slides from my talk on functional programming in Python, which I presented a few days ago at <a href="http://python-krakow.blogspot.com/2008/01/agenda-pierwszego-spotkania.html">the first meeting of Pythonistas</a> in Kraków (the slides are in Polish only, sorry). Feel free to leave your comments!</p>
<div align="center"><object style="margin:0px" width="425" height="355">
<param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=programowanie-funkcyjne-w-pythonie-1201559915977654-4"/>
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=programowanie-funkcyjne-w-pythonie-1201559915977654-4" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>
<p><strong>Update 2008-04-24:</strong> Slides are also <a href="http://www.adambyrtek.net/2008/04/24/why-its-good-to-be-lazy/">available in English</a>.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Functional+programming+in+Python&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F01%2F30%2Ffunctional-programming-in-python%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/01/30/functional-programming-in-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Agile goes underground</title>
		<link>http://www.adambyrtek.net/2008/01/30/agile-goes-underground/</link>
		<comments>http://www.adambyrtek.net/2008/01/30/agile-goes-underground/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 10:37:26 +0000</pubDate>
		<dc:creator>Adam Byrtek</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[agile]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[krakow]]></category>

		<guid isPermaLink="false">http://www.adambyrtek.net/2008/01/30/agile-goes-underground/</guid>
		<description><![CDATA[About a year ago I had an idea to run an informal Open Space event here in Kraków, to gather a group of people interested in Agile methods of software development. At that time there was little or no interest, so my motivation slowly decreased. But a few weeks ago I met with Kuba, who [...]<script type="text/javascript">SHARETHIS.addEntry({ title: "Agile goes underground", url: "http://www.adambyrtek.net/2008/01/30/agile-goes-underground/" });</script>]]></description>
			<content:encoded><![CDATA[<p>About a year ago <a href="http://groups.google.com/group/polish-agile-user-group/msg/e4d972d3c55fe946">I had an idea</a> to run an informal <a href="http://www.openspaceworld.org/">Open Space</a> event here in Kraków, to gather a group of people interested in Agile methods of software development. At that time there was little or no interest, so my motivation slowly decreased. But a few weeks ago I met with <a href="http://jakub.dziwisz.org">Kuba</a>, who had a very similar idea some time ago, and we decided to take a try. After a few days of quick (and quite dirty) preparations  we are proud to invite you to the first iteration of <a href="http://underground.agile.org.pl">Agile Underground</a>, an event which will take place on <em>Feb 28th</em> here in Kraków.</p>
<p><a href="http://sharethis.com/item?&wp=2.3.3&amp;publisher=d991b43e-129e-4dd8-83a1-2050bced0b10&amp;title=Agile+goes+underground&amp;url=http%3A%2F%2Fwww.adambyrtek.net%2F2008%2F01%2F30%2Fagile-goes-underground%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.adambyrtek.net/2008/01/30/agile-goes-underground/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
