<?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>Guilherme Chapiewski &#187; Programming</title>
	<atom:link href="http://guilherme.pro/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://guilherme.pro</link>
	<description>Software Development stuff</description>
	<lastBuildDate>Wed, 06 Apr 2011 04:51:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>Titanium Mobile hack: execute your projects from the command line using Make</title>
		<link>http://guilherme.pro/2011/04/06/titanium-mobile-hack-execute-your-projects-from-the-command-line-using-make/</link>
		<comments>http://guilherme.pro/2011/04/06/titanium-mobile-hack-execute-your-projects-from-the-command-line-using-make/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 04:26:26 +0000</pubDate>
		<dc:creator>Guilherme Chapiewski</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Appcelerator]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Titanium Mobile]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://guilherme.pro/?p=160</guid>
		<description><![CDATA[Appcelerator&#8217;s Titanium Mobile is a nice platform to develop native iOS (and Android) applications using JavaScript. Unlike other platforms that provide only a web container to run web applications that pretend to be native, Titanium translates JavaScript code into native applications that look and behave like they were written in Objective-C. To run Titanium applications [...]]]></description>
			<content:encoded><![CDATA[<p>Appcelerator&#8217;s <a href="http://www.appcelerator.com/products/titanium-mobile-application-development/" onclick="pageTracker._trackPageview('/outgoing/www.appcelerator.com/products/titanium-mobile-application-development/?referer=');">Titanium Mobile</a> is a nice platform to develop native <a href="http://developer.apple.com/ios" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/ios?referer=');">iOS</a> (and <a href="http://www.android.com" onclick="pageTracker._trackPageview('/outgoing/www.android.com?referer=');">Android</a>) applications using <a href="http://en.wikipedia.org/wiki/JavaScript" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/JavaScript?referer=');">JavaScript</a>. Unlike other platforms that provide only a web container to run web applications that pretend to be native, Titanium translates JavaScript code into native applications that look and behave like they were written in <a href="http://en.wikipedia.org/wiki/Objective-C" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Objective-C?referer=');">Objective-C</a>.</p>
<p>To run Titanium applications you need to use <a href="http://www.appcelerator.com/products/download/" onclick="pageTracker._trackPageview('/outgoing/www.appcelerator.com/products/download/?referer=');">Titanium Developer</a>. This program executes a bunch of scripts to compile your projects using <a href="http://developer.apple.com/technologies/tools/xcode.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/technologies/tools/xcode.html?referer=');">Xcode</a>, starts the application in iOS simulator and so on. Fortunately Titanium is <a href="http://github.com/appcelerator/titanium_mobile" onclick="pageTracker._trackPageview('/outgoing/github.com/appcelerator/titanium_mobile?referer=');">open sourced on Github</a>, and while reading its code I had an idea that would make me feel much more comfortable about running my Titanium applications. If you are a &#8220;command-liner&#8221; like me, you probably will prefer to execute your applications from your <a href="http://en.wikipedia.org/wiki/Unix_shell" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Unix_shell?referer=');">shell</a> using <a href="http://en.wikipedia.org/wiki/Make_%28software%29" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Make_28software_29?referer=');">Makefiles</a>, and that&#8217;s what my hack is all about.</p>
<p>The first thing I did was to understand how Titanium starts its projects and write a command-line script that replicates this behavior. Titanium uses a script called <strong>builder.py</strong> to do all the magic, and I wrote a simple wrapper script called <strong><a href="https://gist.github.com/905076" onclick="pageTracker._trackPageview('/outgoing/gist.github.com/905076?referer=');">titanium.sh</a></strong> that uses <strong>builder.py</strong> to compile and start the application:</p>
<p><script src="https://gist.github.com/905076.js?file=titanium.sh"></script></p>
<p>You will notice in the script source that I read some data (the application name and ID) from <strong>tiapp.xml</strong>. This is the file used by Titanium to store projects&#8217; metadata. if you want to use this script in your projects, it&#8217;s important to change the <strong>tiapp.xml</strong> path according to your project structure. My projects usually have a structure like this:</p>
<pre>
/bin (directory)
    titanium.sh
/SampleApp (directory)
Makefile
</pre>
<p>&#8230; where:</p>
<ul>
<li><strong>bin</strong> is the directory where I put <strong>titanium.sh</strong> and other utility scripts.</li>
<li><strong>SampleApp</strong> is the directory where my application lives (this directory has the same name of my application).</li>
<li><strong>Makefile</strong> lives in the root directory.</li>
</ul>
<p>If you use this same project structure, your <strong>tiapp.xml</strong> file will be located at <strong>/SampleApp/tiapp.xml</strong>. In this case, just copy my script and it will work for you too.</p>
<p>You can also configure Titanium and iOS SDK versions that will be used to compile. Just change the values of <strong>*_SDK_VERSION</strong> variables to the versions you have installed in your computer. Some variables (like <strong>PROJECT_NAME</strong>) are parameters that will be passed when the script is called (in our case, this will be informed by the <strong>Makefile</strong>).</p>
<p>One last thing about <strong>titanium.sh</strong> is that I use some <a href="http://en.wikipedia.org/wiki/Perl" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Perl?referer=');">Perl</a> &#8220;black magic&#8221; at the end of the script to produce beautiful colored output depending on the log type (info, debug, error, etc.) &#8211; just like Titanium Developer does:</p>
<p><img src="http://guilherme.pro/wp-content/uploads/2011/04/titanium-make.png" alt="" title="Titanium Mobile Makefile" width="450" height="400" class="aligncenter size-full wp-image-171" align="center" /></p>
<p>After that, you will just need a simple <a href="https://gist.github.com/905076" onclick="pageTracker._trackPageview('/outgoing/gist.github.com/905076?referer=');">Makefile</a> that will allow you to start the application by simply typing &#8220;make run&#8221; at the command line:</p>
<p><script src="https://gist.github.com/905076.js?file=Makefile"></script></p>
<p>The <strong>Makefile</strong> is responsible for calling <strong>titanium.sh</strong> passing all the necessary variables. Just copy <a href="https://gist.github.com/905076" onclick="pageTracker._trackPageview('/outgoing/gist.github.com/905076?referer=');">my Makefile</a> to your project root, change the <strong>PROJECT_NAME</strong> variable and you are good to go!</p>
<p>If you want to take a look on how I use these scripts in my projects, take a look at <a href="http://github.com/guilhermechapiewski/titanium-jasmine" onclick="pageTracker._trackPageview('/outgoing/github.com/guilhermechapiewski/titanium-jasmine?referer=');">titanium-jasmine on GitHub</a>. You will notice in this project that you can do a lot of other fancy stuff using Make.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fguilherme.pro%2F2011%2F04%2F06%2Ftitanium-mobile-hack-execute-your-projects-from-the-command-line-using-make%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://guilherme.pro/2011/04/06/titanium-mobile-hack-execute-your-projects-from-the-command-line-using-make/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Refactoring: Do it all the time!</title>
		<link>http://guilherme.pro/2010/12/20/refactoring-do-it-all-the-time/</link>
		<comments>http://guilherme.pro/2010/12/20/refactoring-do-it-all-the-time/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 21:13:18 +0000</pubDate>
		<dc:creator>Guilherme Chapiewski</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Martin Fowler]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Wikipedia]]></category>

		<guid isPermaLink="false">http://guilherme.pro/?p=138</guid>
		<description><![CDATA[Refactoring is a very well known technique that has been used for years in the software development field. Here are some popular definitions: &#8220;Code refactoring is the process of changing a computer program&#8217;s source code without modifying its external functional behavior in order to improve some of the nonfunctional attributes of the software. Advantages include [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Refactoring</strong> is a very well known technique that has been used for years in the software development field. Here are some popular definitions:</p>
<blockquote><p><em>&#8220;Code refactoring is the process of changing a computer program&#8217;s source code without modifying its external functional behavior in order to improve some of the nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve the maintainability of the source code, as well as a more expressive internal architecture or object model to improve extensibility.&#8221;</em><br />&#8211; <a href="http://en.wikipedia.org/wiki/Code_refactoring" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Code_refactoring?referer=');">Wikipedia</a></p></blockquote>
<p>Or, being more concise:</p>
<blockquote><p><em>&#8220;A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.&#8221;</em><br />&#8211; <a href="http://martinfowler.com/bliki/DefinitionOfRefactoring.html" onclick="pageTracker._trackPageview('/outgoing/martinfowler.com/bliki/DefinitionOfRefactoring.html?referer=');">Martin Fowler</a></p></blockquote>
<p>My concern with Refactoring is that most people don&#8217;t realize that they will have much more benefits if they do it <strong>all the time</strong>.</p>
<p>As the definition above explains, the purpose of Refactoring is to make code easier to change over time. It doesn&#8217;t make sense to keep adding features to your code for, say, 10 months and then stop-the-world for a couple of weeks to refactor it. <strong>If you&#8217;re doing that, you&#8217;re totally missing the point.</strong> In this hypothetical situation, not only (1) it would become more complex to make changes in the software over time &#8211; and you&#8217;d be in trouble for several months &#8211; but also (2) at some point of time the team would have to stop and re-engineer everything &#8211; because the software would become very difficult to change.</p>
<p>If a team waits for 10 months, or 2 months, or 2 weeks to refactor something, they are doing it wrong. Each time new features are added the code becomes more complex, and it&#8217;s necessary to review it as soon as possible to make the necessary improvements. If the team doesn&#8217;t do that often, they will become slower and slower each day, they will be less productive and deliver much less features (or value).</p>
<p>The &#8220;re-engineer&#8221; thing even worse. First, teams that stop to make huge refactorings are delivering <strong>nothing</strong> to their customers while doing that because they&#8217;re too busy <strong>fixing their own mess</strong>. It&#8217;s definitely bad to pay a software team to deliver nothing. Second (and more important), huge refactorings are often risky, because they change a great amount of code and software components, usually introducing bugs and unexpected behaviors.</p>
<p>To avoid all these bad things, <strong>you must do refactoring every day, all the time!</strong></p>
<p><img src="http://guilherme.pro/wp-content/uploads/2010/12/red_green_refactor1.jpg" alt="(1) Red, (2) Green, (3) Refactor" title="(1) Red, (2) Green, (3) Refactor" width="150" height="88" class="alignleft size-full wp-image-148" align="left" />Every time you make a change, you must look for an opportunity to make an improvement. If you keep doing that, your code will always be clean, maintainable and easy to modify. Remember the TDD cycle: <a href="http://jamesshore.com/Blog/Red-Green-Refactor.html" onclick="pageTracker._trackPageview('/outgoing/jamesshore.com/Blog/Red-Green-Refactor.html?referer=');">Red-Green-Refactor</a>? <strong>Don&#8217;t miss the refactor part, do it all the time!</strong></p>
<p>In my experience it takes no more than a few minutes to refactor if you are doing it in small chunks all the time, and more importantly, this will keep you from stopping to make huge and risky software re-writes.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fguilherme.pro%2F2010%2F12%2F20%2Frefactoring-do-it-all-the-time%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://guilherme.pro/2010/12/20/refactoring-do-it-all-the-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Coding Dojo SP @ Yahoo! Brazil</title>
		<link>http://guilherme.pro/2010/08/06/coding-dojo-sp-yahoo-brazil/</link>
		<comments>http://guilherme.pro/2010/08/06/coding-dojo-sp-yahoo-brazil/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 22:26:47 +0000</pubDate>
		<dc:creator>Guilherme Chapiewski</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Coding Dojo]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Randori]]></category>
		<category><![CDATA[Yahoo!]]></category>
		<category><![CDATA[Yahoo! Developer Network]]></category>

		<guid isPermaLink="false">http://guilherme.pro/?p=127</guid>
		<description><![CDATA[Last Friday (July 30th) we hosted at Yahoo! Brazil&#8216;s office our first Coding Dojo SP group meeting! The meeting was really cool and very crowded. We had a Randori session with around 30 developers to solve the &#8220;write numbers to words&#8221; problem using Python (thanks to the influence of our Pythonist friend &#8220;rbp&#8220;, that led [...]]]></description>
			<content:encoded><![CDATA[<p>Last Friday (July 30th) we hosted at <a href="http://br.yahoo.com" onclick="pageTracker._trackPageview('/outgoing/br.yahoo.com?referer=');">Yahoo! Brazil</a>&#8216;s office our first <a href="http://www.dojosp.org" onclick="pageTracker._trackPageview('/outgoing/www.dojosp.org?referer=');">Coding Dojo SP</a> group meeting!</p>
<p><img src="http://guilherme.pro/wp-content/uploads/2010/08/dojo_mosaic.jpg" alt="Coding Dojo @ Yahoo!" title="Coding Dojo @ Yahoo!" width="450" height="245" class="aligncenter size-full wp-image-129" align="center" /></p>
<p>The meeting was really cool and very crowded. <img src='http://guilherme.pro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We had a <a href="http://codingdojo.org/cgi-bin/wiki.pl?RandoriKata" onclick="pageTracker._trackPageview('/outgoing/codingdojo.org/cgi-bin/wiki.pl?RandoriKata&amp;referer=');">Randori</a> session with around 30 developers to solve the &#8220;write numbers to words&#8221; problem using <a href="http://python.org" onclick="pageTracker._trackPageview('/outgoing/python.org?referer=');">Python</a> (thanks to the influence of our Pythonist friend &#8220;<a href="http://isnomore.net" onclick="pageTracker._trackPageview('/outgoing/isnomore.net?referer=');">rbp</a>&#8220;, that led the Dojo session).</p>
<p>I just finished writing a <a href="http://developer.yahoo.net/blog/archives/2010/08/coding_dojo_sao_paulo.html" onclick="pageTracker._trackPageview('/outgoing/developer.yahoo.net/blog/archives/2010/08/coding_dojo_sao_paulo.html?referer=');">post on Yahoo! Developer Network&#8217;s blog explaining in more details how the meeting was</a> (and what the heck a <a href="http://codingdojo.org" onclick="pageTracker._trackPageview('/outgoing/codingdojo.org?referer=');">Coding Dojo</a> is). You can also see some <a href="http://www.flickr.com/photos/guilhermechapiewski/sets/72157624640168810/" onclick="pageTracker._trackPageview('/outgoing/www.flickr.com/photos/guilhermechapiewski/sets/72157624640168810/?referer=');">pictures on my Flickr page</a>.</p>
<p>The next meeting will be next week (we still have to define the date). Subscribe to the <a href="http://groups.google.com/group/dojo_sp/" onclick="pageTracker._trackPageview('/outgoing/groups.google.com/group/dojo_sp/?referer=');">group&#8217;s mailing list</a> to be notified about the next meetings.</p>
<p>See you next time here in the office! <img src='http://guilherme.pro/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fguilherme.pro%2F2010%2F08%2F06%2Fcoding-dojo-sp-yahoo-brazil%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://guilherme.pro/2010/08/06/coding-dojo-sp-yahoo-brazil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I don&#8217;t write code comments</title>
		<link>http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/</link>
		<comments>http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 07:43:25 +0000</pubDate>
		<dc:creator>Guilherme Chapiewski</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Fluent Interfaces]]></category>
		<category><![CDATA[Fluent Mail API]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaMail]]></category>

		<guid isPermaLink="false">http://guilherme.pro/?p=47</guid>
		<description><![CDATA[These days I was configuring some personal projects on ohloh and one thing called my attention. Ohloh showed the message &#8220;very few source code comments&#8221; in all my projects. This is no surprise to me. I really don&#8217;t like to write source code comments. Why? Because if my code isn&#8217;t clear and easy enough for [...]]]></description>
			<content:encoded><![CDATA[<p>These days I was configuring some personal projects on <a href="http://www.ohloh.net/" onclick="pageTracker._trackPageview('/outgoing/www.ohloh.net/?referer=');">ohloh</a> and one thing called my attention. Ohloh showed the message <em>&#8220;very few source code comments&#8221;</em> in all my projects.</p>
<p>This is no surprise to me. I really don&#8217;t like to write source code comments. Why? Because if my code isn&#8217;t clear and easy enough for one to read and easily understand, I need to refactor. Many times I ask friends to take a look at code snippets and check if they understand. When they don&#8217;t, the method is usually too big or the variable/method names are not clear enough, and then I refactor to make it better to understand.</p>
<p>One example that I love (and use in many presentations) is the code to send e-mails using <a href="http://java.sun.com/products/javamail/" onclick="pageTracker._trackPageview('/outgoing/java.sun.com/products/javamail/?referer=');">Java Mail API</a>. The code would be something like this (from <a href="http://www.javaworld.com/javaworld/jw-06-1999/jw-06-javamail.html?page=4" onclick="pageTracker._trackPageview('/outgoing/www.javaworld.com/javaworld/jw-06-1999/jw-06-javamail.html?page=4&amp;referer=');">Java World tutorial</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// create some properties and get the default Session</span>
<span style="color: #003399;">Properties</span> props <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Properties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtp.host&quot;</span>, _smtpHost<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Session session <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getDefaultInstance</span><span style="color: #009900;">&#40;</span>props, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create a message</span>
Address replyToList<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>replyTo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
Message newMessage <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMessage<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_fromName <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    newMessage.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>from,
        _fromName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; on behalf of &quot;</span> <span style="color: #339933;">+</span> replyTo<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">else</span>
    newMessage.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    newMessage.<span style="color: #006633;">setReplyTo</span><span style="color: #009900;">&#40;</span>replyToList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    newMessage.<span style="color: #006633;">setRecipients</span><span style="color: #009900;">&#40;</span>Message.<span style="color: #006633;">RecipientType</span>.<span style="color: #006633;">BCC</span>, 
            _toList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    newMessage.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    newMessage.<span style="color: #006633;">setSentDate</span><span style="color: #009900;">&#40;</span>sentDate<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// send newMessage</span>
Transport transport <span style="color: #339933;">=</span> session.<span style="color: #006633;">getTransport</span><span style="color: #009900;">&#40;</span>SMTP_MAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
transport.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span>_smtpHost, _user, _password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
transport.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>newMessage, _toList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I know that this is just an example but <strong>you know</strong> that it&#8217;s not difficult to find monsters like this one in production code.</p>
<p>This code is <strong>so difficult</strong> to read that the programmer had to say what he was doing, otherwise nobody would understand its purpose. There is a lot of infrastructure and business code together resulting on a huge <a href="http://en.wikipedia.org/wiki/Leaky_abstraction" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Leaky_abstraction?referer=');">abstraction leak</a>.</p>
<p>Now take a look at the following code (from <a href="http://code.google.com/p/fluentmailapi/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/fluentmailapi/?referer=');">Fluent Mail API</a>) and tell me how many seconds do you need to understand what the code does:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">new</span> EmailMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;demo@guilhermechapiewski.com&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">to</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination@address.com&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">withSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fluent Mail API&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">withBody</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Demo message&quot;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is an extreme example, of course. Maybe you will not write <a href="http://martinfowler.com/bliki/FluentInterface.html" onclick="pageTracker._trackPageview('/outgoing/martinfowler.com/bliki/FluentInterface.html?referer=');">Fluent Interfaces</a> for every little thing you need in your code, but if you add just a little bit of organization (using a better abstraction) it will already improve code readability:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Email <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Email<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> from, <span style="color: #003399;">String</span> to, ...<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFrom<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> from<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setTo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> to<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ... <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// put your complicated Java Mail code here</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Just by encapsulating the code in an abstraction that makes sense the <a href="http://en.wiktionary.org/wiki/wtf" onclick="pageTracker._trackPageview('/outgoing/en.wiktionary.org/wiki/wtf?referer=');">WTF</a> effect will be sensibly reduced. The programmers can now at least assume that the code sends e-mail messages since it&#8217;s included in a class called &#8220;Email&#8221;.</p>
<p>And that&#8217;s the point. When I create a culture of prohibiting myself from writing code comments, I&#8217;m obligating me to write easy, maintainable and understandable code.</p>
<p>That&#8217;s very extreme, I know, but the results of this approach are awesome.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fguilherme.pro%2F2009%2F04%2F05%2Fwhy-i-dont-write-code-comments%2F&amp;layout=standard&amp;show_faces=true&amp;width=500&amp;action=like&amp;font=segoe+ui&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:80px;" allowTransparency="true"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

