<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Iulian Dogariu</title>
	
	<link>http://www.iuliandogariu.com</link>
	<description>Who Spilled the Java Beans?</description>
	<lastBuildDate>Tue, 23 Feb 2010 11:45:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/WhoSpilledTheJavaBeans" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="whospilledthejavabeans" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Finding free disk space in Ruby</title>
		<link>http://www.iuliandogariu.com/2008/12/finding-free-disk-space-in-ruby/</link>
		<comments>http://www.iuliandogariu.com/2008/12/finding-free-disk-space-in-ruby/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 11:28:33 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=177</guid>
		<description><![CDATA[UPDATED I can&#8217;t find a standard Ruby idiom for finding out the free/occupied disk space on a partition, so here&#8217;s a hack for doing it under Linux:
123456789def disk_used_space&#40; path &#41;
&#160; `df -Pk #{path} &#124;grep ^/ &#124; awk '{print $3;}'`.
&#160; &#160; to_i * 1.kilobyte
end

def disk_free_space&#40; path &#41;
&#160; `df -Pk #{path} &#124;grep ^/ &#124; awk '{print $4;}'`.
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATED</strong> I can&#8217;t find a standard Ruby idiom for finding out the free/occupied disk space on a partition, so here&#8217;s a hack for doing it under Linux:</p>
<div class="codecolorer-container ruby blackboard" 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 /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">def</span> disk_used_space<span style="color:#006600; font-weight:bold;">&#40;</span> path <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#996600;">`df -Pk #{path} |grep ^/ | awk '{print $3;}'`</span>.<br />
&nbsp; &nbsp; <span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">*</span> 1.<span style="color:#9900CC;">kilobyte</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">def</span> disk_free_space<span style="color:#006600; font-weight:bold;">&#40;</span> path <span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#996600;">`df -Pk #{path} |grep ^/ | awk '{print $4;}'`</span>.<br />
&nbsp; &nbsp; <span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">*</span> 1.<span style="color:#9900CC;">kilobyte</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>The <tt>-P</tt> (POSIX compliant output) argument to <tt>df</tt> is important, it forces the output to be more regular, thus easier to parse. Without -P, you&#8217;ll run into trouble if the names of the disk devices are particularly long, e.g. if the machine uses LVM:</p>
<pre>
mymachine:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0               9614052   2819896   6305788  31% /
/dev/mapper/storage-s1
                     331624912    395808 314383488   1% /mnt/s1
/dev/mapper/storage-s2
                     109681544    192248 103917712   1% /mnt/s2
</pre>
<p>The <tt>1.kilobyte</tt> idiom is available only if you use ActiveSupport, e.g. in a Rails application. If you can&#8217;t use ActiveSupport, just write 1024 instead.</p>
<p>Update: the <tt>-P</tt> option is not enough, you should also use <tt>-k</tt> to get the output in 1 KB blocks. Thanks to commenter Martin Rehfeld for the tip.</p>
<p>Hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2008/12/finding-free-disk-space-in-ruby/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Naming and Some Common String and Array Patterns</title>
		<link>http://www.iuliandogariu.com/2008/09/naming-and-some-common-string-and-array-patterns/</link>
		<comments>http://www.iuliandogariu.com/2008/09/naming-and-some-common-string-and-array-patterns/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 14:39:39 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=126</guid>
		<description><![CDATA[How many times have you had to display a list of items like this:
1apples - oranges - ququxes - bananas
The newbie programmer (like I myself was and still am in many respects) will often hammer out this piece of code:
1234567String output = &#34;&#34;;
for&#40; int i = 0; i &#60; fruits.size&#40;&#41;; i++ &#41; &#123;
&#160; output += [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How many times</strong> have you had to display a list of items like this:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">apples - oranges - ququxes - bananas</div></td></tr></tbody></table></div>
<p>The newbie programmer (like I myself was and still am in many respects) will often hammer out this piece of code:</p>
<div class="codecolorer-container java blackboard" 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 /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003399;">String</span> output <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> fruits.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; output <span style="color: #339933;">+=</span> fruits.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; output <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot; - &quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">// Now remove the last separator</span><br />
output <span style="color: #339933;">=</span> output.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span> 0, output.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> 3 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Hey, this is convoluted and ugly. There should be a library function that does this for us. Everybody uses arrays and strings. This is such a basic problem that someone must have already implemented it in some library somewhere, if it&#8217;s not already in our language&#8217;s standard library.</p>
<p>So let&#8217;s turn to Google, to find a library that can save us.</p>
<p>But &#8230; what search terms should we use?</strong></p>
<p>In other words, <strong>what is this problem&#8217;s name?</strong></p>
<p><iframe src="http://rcm.amazon.com/e/cm?t=whospithejavb-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=0262011530&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr" style="width:120px;height:240px;float:right;" scrolling="no" marginwidth="5" marginheight="0" frameborder="0"></iframe></p>
<p><strong>Once you can name something, you can master it.</strong> This is a thought that stuck with me while reading the classic introductory textbook to programming, <em>Structure and Interpretation of Computer Programs</em>.</p>
<p>We learn new words, and even make up new words, because it helps us communicate and understand ideas and thoughts of ever increasing complexity.</p>
<p>Take a simple sentence, like <em>The government will lower taxes</em>. Now try to express the same idea, <strong>with the same precision</strong>, but without using the words <em>government</em>, or <em>taxes</em>. You&#8217;ll end up with something like: &#8220;The body of individuals elected by the people of a country, with a limited-time mandate to run the country, will lower the amount that each individual must contribute to support the country&#8217;s shared expenses.&#8221; Not pretty, by any measure.</p>
<p>Enough with the theory, let&#8217;s return to the craft of programming.</p>
<p>There exist a bunch of simple but very common problems, involving arrays and strings. And I want to remind you that <strong>they have names</strong>, and how important it is to know these names. It will help you not only in finding the right library call to do what you are trying to do, but it will also help you recognise these problems in your day to day programming work. You&#8217;ll be able to think <em>Hey, this looks like a <tt>map</tt> followed by a <tt>select</tt>, I know exactly how to solve it quickly and elegantly</em>.</p>
<h3><tt>join</tt></h3>
<p>Let&#8217;s backtrack for a minute to the start of this post. What we have there is a problem that can be summarised as:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[&quot;apples&quot;, &quot;oranges&quot;, &quot;ququxes&quot;, &quot;bananas&quot;]<br />
=&gt; &quot;apples - oranges - ququxes - bananas&quot;</div></td></tr></tbody></table></div>
<p>In plain English: we have an array of strings and we want to join together these items into a single string, with a separator string in between the items.</p>
<p>This problem has a classic name, it&#8217;s called a <strong>join</strong>.</p>
<p>Now we know how this problem is called, we can master it. We started out this example in Java, so we&#8217;ll have to find a Java library function that does <tt>join</tt>. And sure enough, commons-lang&#8217;s <a href="http://commons.apache.org/lang/apidocs/org/apache/commons/lang/StringUtils.html">StringUtils</a> class has a helpful little method called <tt>join()</tt>.</p>
<p>Side note: If you use one of the more friendly languages out there, like Python or Ruby, you&#8217;ve got it easier. In Ruby it&#8217;s as simple as:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">irb(main):001:0&gt; [&quot;apples&quot;, &quot;oranges&quot;, &quot;ququxes&quot;, &quot;bananas&quot;].join(&quot; - &quot;)<br />
=&gt; &quot;apples - oranges - ququxes - bananas&quot;</div></td></tr></tbody></table></div>
<h3><tt>split</tt></h3>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&quot;apples - oranges - ququxes - bananas&quot;<br />
=&gt; [&quot;apples&quot;, &quot;oranges&quot;, &quot;ququxes&quot;, &quot;bananas&quot;]</div></td></tr></tbody></table></div>
<p>This is the reverse of <tt>join</tt>. Take a string of items separated by a delimiter, and return an array of the individual item strings.</p>
<p>There&#8217;s a <tt>split</tt> function in the standard library of Python, Ruby, PHP, even Java. Oh yeah, in Java it&#8217;s as simple as <tt>string.split(pattern)</tt>.</p>
<h3><tt>zip</tt></h3>
<p>A <tt>zip</tt> operation, also called <tt>combine</tt>, means pairing each corresponding item from two arrays:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[&quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;]<br />
[31, &nbsp; &nbsp;28, &nbsp; &nbsp; 31, &nbsp; &nbsp;30, &nbsp; &nbsp; 31, &nbsp; &nbsp; 30 &nbsp; ]<br />
=&gt; [&quot;Jan&quot;, 31],<br />
[&quot;Feb&quot;, 28],<br />
[&quot;Mar&quot;, 31],<br />
[&quot;Apr&quot;, 30],<br />
[&quot;May&quot;, 31],<br />
[&quot;Jun&quot;, 30]</div></td></tr></tbody></table></div>
<p>It&#8217;s called <a href="http://www.php.net/manual/en/function.array-combine.php"><tt>array_combine()</tt></a> in PHP, and <a href="http://www.ruby-doc.org/core-1.8.7/classes/Enumerable.html"><tt>zip</tt></a> in Ruby.</p>
<h3><tt>flatten</tt></h3>
<p>Taking a nested array (aka array of arrays) and turning it into a, err, flat array:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[&quot;one&quot;, [&quot;two&quot;, &quot;three&quot;], &quot;four&quot;, [&quot;five&quot;, [&quot;six&quot;, &quot;seven&quot;]]]<br />
=&gt; [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;, &quot;four&quot;, &quot;five&quot;, &quot;six&quot;, &quot;seven&quot;]</div></td></tr></tbody></table></div>
<h3><tt>map</tt></h3>
<p><tt>map</tt>, also called <tt>collect</tt>, transforms each item of an array through a function that you specify, and returns an array of the transformed values. Classic example: finding out the squares of the first positive integers:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[1, 2, 3, 4, 5, 6]<br />
=&gt; [1, 4, 9, 16, 25, 36]</div></td></tr></tbody></table></div>
<p>To achieve this, you pass in a function that takes the argument x and returns x*x. Exactly how you do this varies according to your language. In some languages it&#8217;s braindead simple (<a href="http://www.ruby-doc.org/core-1.8.7/classes/Enumerable.html#M001146">Ruby</a>), in others it requires a bit more work but still reasonably simple (<a href="http://www.php.net/manual/en/function.array-map.php">PHP</a>, <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/CollectionUtils.html#collect(java.util.Collection,%20org.apache.commons.collections.Transformer)">Java</a>)</p>
<h3><tt>reduce</tt></h3>
<p><tt>reduce</tt>, also called <tt>inject</tt>, combines all the values of an array using a function that you specify, to create a single value. Simple example: the sum of all the elements of an array of numbers:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[1, 2, 3, 4, 5, 6]<br />
=&gt; 21</div></td></tr></tbody></table></div>
<p>is a <tt>reduce</tt> operation where you pass a function of two arguments a and b that returns a+b.</p>
<p>Just like with <tt>map</tt> above, how you do it varies according to your language. Take a look at <a href="http://www.ruby-doc.org/core-1.8.7/classes/Enumerable.html#M001148">Ruby</a>, <a href="http://www.php.net/manual/en/function.array-reduce.php">PHP</a>. I can&#8217;t find a similar function for Java, if you know any, please react in the comments section <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3><tt>select</tt>, <tt>reject</tt></h3>
<p>These are filters, they retain or remove items from an array according to a function you pass in.</p>
<p>Let&#8217;s filter only the items that start with a vowel:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;plum&quot;]<br />
=&gt; [&quot;apple&quot;, &quot;orange&quot;]</div></td></tr></tbody></table></div>
<p>All you do is call &#8220;select&#8221; and pass in a function that returns true if its argument starts with a vowel. That&#8217;s a function you&#8217;ll have to build for yourself, sorry <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p><tt>reject</tt> works the same way but returns the items that do <em>not</em> match the function. Using the same function as above, a call to <tt>reject</tt> works this way:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;plum&quot;]<br />
=&gt; [&quot;banana&quot;, &quot;cherry&quot;, &quot;plum&quot;]</div></td></tr></tbody></table></div>
<p>Of course, if your language or libraries don&#8217;t provide a <tt>reject</tt> call, you can use <tt>select</tt> and pass in a function that returns false when it was supposed to return true.</p>
<p>Have a look at <a href="http://www.php.net/manual/en/function.array-filter.php"><tt>array_filter</tt></a> if you&#8217;re using PHP, <a href="http://www.ruby-doc.org/core-1.8.7/classes/Enumerable.html#M001143"><tt>select</tt></a> or <a href="http://www.ruby-doc.org/core-1.8.7/classes/Enumerable.html#M001144"><tt>reject</tt></a> if you&#8217;re using Ruby, or commons-collections&#8217; <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/CollectionUtils.html#select(java.util.Collection,%20org.apache.commons.collections.Predicate)"><tt>select</tt></a> and <a href="http://commons.apache.org/collections/api-release/org/apache/commons/collections/CollectionUtils.html#selectRejected(java.util.Collection,%20org.apache.commons.collections.Predicate)"><tt>selectRejected</tt></a> if you&#8217;re using Java.</p>
<p>OK, kids, I hope you learned something today <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Start recognising common patterns like <tt>join</tt> or <tt>map</tt> in the code that you write, and start thinking in terms of them.</p>
<p>Please feel free to suggest additional code samples and links for the languages I have not covered.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2008/09/naming-and-some-common-string-and-array-patterns/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Not a minute too soon</title>
		<link>http://www.iuliandogariu.com/2008/07/not-a-minute-too-soon/</link>
		<comments>http://www.iuliandogariu.com/2008/07/not-a-minute-too-soon/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 10:11:41 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=113</guid>
		<description><![CDATA[37signals announces their end of support for IE 6. They are actually the second high-profile web app developer to drop IE 6, after Apple did the same with MobileMe. The snowball is rolling. The lives of web developers will improve dramatically when they will no longer have to ensure support for the decrepit browser that [...]]]></description>
			<content:encoded><![CDATA[<p>37signals <a href="http://37signals.blogs.com/products/2008/07/basecamp-phasin.html">announces their end of support for IE 6</a>. They are actually the second high-profile web app developer to drop IE 6, after Apple did the same with MobileMe. The snowball is rolling. The lives of web developers will improve dramatically when they will no longer have to ensure support for the decrepit browser that IE 6 is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2008/07/not-a-minute-too-soon/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript 2: An alternative proposal</title>
		<link>http://www.iuliandogariu.com/2008/02/javascript-2-an-alternative-proposal/</link>
		<comments>http://www.iuliandogariu.com/2008/02/javascript-2-an-alternative-proposal/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 10:57:29 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=97</guid>
		<description><![CDATA[The ECMAScript version 4 specification is almost ready. ECMAScript 4 will be the basis of JavaScript 2. And, omg, it&#8217;s huge! Like, literally huge. Here you can read a digest of the proposed language features.
I feel that the proposal is non-orthogonal (read: bloated) in many ways. The new language will have both class-based OOP, a [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.ecmascript.org/">ECMAScript</a> version 4 specification is almost ready. ECMAScript 4 will be the basis of JavaScript 2. And, omg, it&#8217;s huge! Like, literally huge. <a href="http://www.ecmascript.org/es4/spec/overview.pdf">Here</a> you can read a digest of the proposed language features.</p>
<p>I feel that the proposal is non-orthogonal (read: bloated) in many ways. The new language will have both class-based OOP, a la Java, <strong>and</strong> prototype-based OOP; packages <strong>and</strong> namespaces as logical units of code; static type annotations both of the <em>nominal</em> kind (this object IS A Thing), and of the <em>structural</em> kind (this object responds LIKE a Thing).</p>
<p>What if, instead of striving to clone Java, they focused on making ECMAScript a more pleasant language to develop in? What if they:</p>
<ul>
<li>added interpolated strings. Yes, I like to write
<div class="codecolorer-container javascript blackboard" 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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello, ${name}, welcome to JS!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>instead of</p>
<div class="codecolorer-container javascript blackboard" 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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello, &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, welcome to JS!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</li>
<li>added a simpler syntax for passing functions as arguments. How about this:
<div class="codecolorer-container javascript blackboard" 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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span>1<span style="color: #339933;">,</span>2<span style="color: #339933;">,</span>3<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">do</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>as syntactic sugar for this JavaScript construct:</p>
<div class="codecolorer-container javascript blackboard" 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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#91;</span>1<span style="color: #339933;">,</span>2<span style="color: #339933;">,</span>3<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
</li>
<li>got rid of nominal types. JavaScript can do OOP really well without classes, and it&#8217;s a shame to shoehorn classes and interfaces into it just to imitate Java and C#</li>
<li>shipped a unit testing framework in the standard library</li>
<li>added useful methods on arrays, like map, inject, detect, any, all</li>
</ul>
<p>Eh? How about you? What do you wish to see in the next major version of Javascript?</p>
<p>Later Edit: Also see <a href="http://www.crockford.com/javascript/recommend.html">Douglas Crockford&#8217;s</a> suggested changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2008/02/javascript-2-an-alternative-proposal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using prototype.js in chrome</title>
		<link>http://www.iuliandogariu.com/2007/02/using-prototypejs-in-chrome/</link>
		<comments>http://www.iuliandogariu.com/2007/02/using-prototypejs-in-chrome/#comments</comments>
		<pubDate>Fri, 09 Feb 2007 02:01:45 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=67</guid>
		<description><![CDATA[Are you writing a Firefox/Thunderbird extension, or maybe a XULRunner app, and want to make use of the Prototype JS library? Then you will run into this issue.
Because of a long-standing bug in Mozilla, Function.prototype cannot be extended with the method &#8216;bind&#8217;, and so all the utilities in Prototype.js that make use of bind() won&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Are you writing a Firefox/Thunderbird extension, or maybe a XULRunner app, and want to make use of the <a href="http://prototypejs.org">Prototype JS library</a>? Then you will run into <a href="http://blog.jeffhaynie.us/xul-enhanced-by-prototype.html">this issue</a>.</p>
<p>Because of a long-standing bug in Mozilla, Function.prototype cannot be extended with the method &#8216;bind&#8217;, and so all the utilities in Prototype.js that make use of bind() won&#8217;t work as expected. Once again, this happens with documents loaded from _chrome_, not with normal web pages.</p>
<p>Steve Conover <a href="http://wrath.rubyonrails.org/pipermail/rails-spinoffs/2006-January/002254.html">posted a workaround</a> for this bug, about a year ago. I&#8217;m happy to offer a <a href="http://www.iuliandogariu.com/wp-content/uploads/2009/05/prototype_150_bind_patch.diff">patch against Prototype 1.5.0 (final)</a>, with that workaround applied. Hope you&#8217;ll find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2007/02/using-prototypejs-in-chrome/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Programming is Not “Construction”</title>
		<link>http://www.iuliandogariu.com/2007/01/programming-is-not-construction/</link>
		<comments>http://www.iuliandogariu.com/2007/01/programming-is-not-construction/#comments</comments>
		<pubDate>Sun, 21 Jan 2007 05:19:54 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[working with programmers]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=63</guid>
		<description><![CDATA[Lots of people who have read Steve McConnell&#8217;s celebrated book Code Complete are living with the impression that programming is, or ought to be, like constructing buildings (civil engineering). After all:
* an architect works out a design, then draws the blueprints of the building, much like a software architect
* you generally don&#8217;t make your own [...]]]></description>
			<content:encoded><![CDATA[<p>Lots of people who have read Steve McConnell&#8217;s celebrated book <a href="http://www.amazon.com/Code-Complete-Second-Steve-McConnell/dp/0735619670">Code Complete</a> are living with the impression that <strong>programming</strong> is, or ought to be, like <strong>constructing buildings</strong> (civil engineering). After all:<br />
* an architect works out a design, then draws the blueprints of the building, much like a software architect<br />
* you generally don&#8217;t make your own bricks and nuts and bolts, you reuse ready-made components, just like we&#8217;re supposed to reuse code in libraries<br />
* there are layers of abstraction: an architect describes a building in more general terms, but the bricklayer has to have precise and low-level instructions on where to put the bricks. Various levels of foremen and managers mediate between the two extremes. In software, you have layers of compilers and code generators that translate a high-level design into binary code.</p>
<p>This looks reasonable.</p>
<p>Only it&#8217;s not. Programming is <strong>fundamentally not like construction</strong>.</p>
<p>* A building&#8217;s <em>functional requirements</em> are simple <strong>and stable</strong>: it has to stand, and it has to provide shelter and adequate sunlight. All the rest is fluff. By contrast, the functional requirements of software are <strong>very complex and often changing</strong>.</p>
<p>* That&#8217;s why software <strong>has to be</strong> malleable. In computing, we have a distinction between hardware and software precisely because hardware is _not_ malleable.</p>
<p>Well-factored software has to change little when requirements change only a little. By contrast, constructions are anything _but_ malleable. If you want to make &#8217;small&#8217; changes to a building, like, say, move a wall 2 metres away, it will cost you dearly, or it might be outright impossible without tearing down the building and starting from scratch.</p>
<p>Actually, construction has more in common with <em>computer hardware</em> than with software. <em>Code Complete</em> would be a great book, if you substituted &#8216;hardware&#8217; for &#8217;software&#8217; all over <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>* Software simply does not have that many physical constraints and limitations to deal with. When you&#8217;re building, you&#8217;re bound by the laws of gravity, by the resilience of your materials, by the shape of the ground, etc., not to mention the city planners <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  By contrast, in software there are little such hard and fast constraints. Hardware has grown cheaper and more powerful, and will  continue to do so. The times when your app <em>had</em> to fit in 640K of RAM are long gone. Most software you&#8217;ll ever work on will _not_ push the limits of available hardware.</p>
<p>* And there are lots of other counter-arguments, e.g. in <a href="http://www.kuro5hin.org/story/2003/3/13/211831/159">this kuro5hin.org article</a>.</p>
<p>&#8220;Metaphors are heuristics, not algorithms. As such, they tend to be a little sloppy&#8221; admits McConnell. However, I&#8217;m mystified why he has chosen maybe the most monstrously sloppy metaphor to describe software development. By the end of Chapter 2, I was literally cringing.</p>
<p>But that isn&#8217;t all.</p>
<p>* The book claims to be for &#8220;Programming Experts&#8221;, but the tone of the writing seems fit for fourth-graders with severe dyslexia. The unfunny pictures don&#8217;t help, either.<br />
* Dynamic languages like Perl or Python are misrepresented, if at all mentioned. The author disdains Python, for example, because it doesn&#8217;t explicitly support&#8230; named constants. Go figure. That&#8217;s like complaining that your new digital watch doesn&#8217;t have a winding knob.<br />
* The book works under the assumption that most of its readers are building intense-load mission-critical software systems, like nuclear bomb simulations, or chemical plant process control software. NEWSFLASH: you aren&#8217;t. If you are, you&#8217;re reading the wrong book anyway. If you aren&#8217;t, but would like to be, you should be reading <a href="http://mitpress.mit.edu/sicp/full-text/book/book.html">SICP</a>, for example.</p>
<p>In conclusion: if you&#8217;re a new or intermediate programmer, I recommend that you skip &#8220;Code Complete&#8221;. It will teach you the wrong way to think about software.</p>
<p>A good introduction to software best practices, one which I warmly recommend, is <a href="http://www.pragmaticprogrammer.com/ppbook/index.shtml">The Pragmatic Programmer</a> by Dave Thomas and Andy Hunt. And if you&#8217;re after a deeper understanding of general and timeless principles of software architecture, you will find Eric S. Raymond&#8217;s <a href="http://www.faqs.org/docs/artu/">Art of Unix Programming</a> particularly enlightening.</p>
<p>But the number one advice is: get coding! Write code, read code written by others, and learn your craft by doing it. Don&#8217;t bother searching for metaphors <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2007/01/programming-is-not-construction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>2006 AD. Microsoft Still Doesn’t Get It</title>
		<link>http://www.iuliandogariu.com/2006/12/2006-ad-microsoft-still-doesnt-get-it/</link>
		<comments>http://www.iuliandogariu.com/2006/12/2006-ad-microsoft-still-doesnt-get-it/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 15:51:47 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=60</guid>
		<description><![CDATA[Yes, they have built a XML user interface language. In their docs and tutorials however, there is no mention of CSS. To define style, you use inline attributes.
Proof once again that VB-itis is a chronic and contagious disease.
Further reading: http://www.devx.com/webdev/Article/20834
]]></description>
			<content:encoded><![CDATA[<p>Yes, they have built a <a href="http://msdn2.microsoft.com/en-us/library/ms752059.aspx">XML user interface language</a>. In their docs and tutorials however, there is no mention of <strong>CSS</strong>. To define style, you use inline attributes.</p>
<p>Proof once again that VB-itis is a chronic and contagious disease.</p>
<p>Further reading: <a href="http://www.devx.com/webdev/Article/20834">http://www.devx.com/webdev/Article/20834</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2006/12/2006-ad-microsoft-still-doesnt-get-it/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Getting groovy with JSON</title>
		<link>http://www.iuliandogariu.com/2006/09/getting-groovy-with-json/</link>
		<comments>http://www.iuliandogariu.com/2006/09/getting-groovy-with-json/#comments</comments>
		<pubDate>Sun, 17 Sep 2006 21:01:13 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=58</guid>
		<description><![CDATA[JSON is an informal standard for describing structured data. It is human-readable, less verbose than XML, and has a distinct advantage which I&#8217;ll mention later.
Short example: say you want to define an address book entry. In JSON it might look like this:
12345&#160;&#123; 'name': 'John Doe',
&#160; &#160;'address': '42, Universe Rd.',
&#160; &#160;'telephone': &#91;&#123;'home': '1-901-555-2323'&#125;,
&#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><a title="JSON" href="http://en.wikipedia.org/wiki/JSON">JSON</a> is an informal standard for describing <strong>structured data</strong>. It is human-readable, less verbose than XML, and has a distinct advantage which I&#8217;ll mention later.</p>
<p>Short example: say you want to define an address book entry. In JSON it might look like this:</p>
<div class="codecolorer-container javascript blackboard" 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 /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'name'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'John Doe'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">'address'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'42, Universe Rd.'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp;<span style="color: #3366CC;">'telephone'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'home'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'1-901-555-2323'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'cell'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'1-888-555-9999'</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#93;</span><br />
&nbsp;<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Compare the verbosity of the above to the equivalent XML here:</p>
<div class="codecolorer-container xml blackboard" 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 /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>John Doe<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>42, Universe Rd.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;telephones<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;telephone</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;home&quot;</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;1-901-555-2323&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;telephone</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;cell&quot;</span> <span style="color: #000066;">number</span>=<span style="color: #ff0000;">&quot;1-888-555-9999&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/telephones<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Using JSON, you can nest <strong>arbitrarily structured</strong> data, making use of maps (comma-separated lists of forms like &#8216;key&#8217;: &#8216;value&#8217;, surrounded by braces) and sequences (comma-separated values, surrounded by brackets).</p>
<p>You can use JSON in lots of places, even in those where the more &#8220;<strong>enterprisey</strong>&#8221; developers would use XML; like, say, to write config files.</p>
<p>However there is a <em>particular affinity</em> between JSON and the <strong><a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX</a></strong> techniques. While doing AJAX you&#8217;ll often find the need to fetch some data from the server and parse it. Guess what: in JavaScript <strong>you don&#8217;t need a parser to parse JSON</strong>, because <strong>JSON syntax is JavaScript syntax</strong>. In other words, you parse it by calling <tt><a href="http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:eval">eval</a>()</tt>.<br />
JSON after all stands for &#8216;JavaScript Object Notation&#8217; <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And, as you probably guessed, <strong>generating </strong>JSON is a breeze. Here&#8217;s a quick&#8217;n'dirty function written in the <a href="http://groovy.codehaus.org">Groovy </a> programming language, that serializes a construct of Java maps and lists into JSON:</p>
<div class="codecolorer-container groovy blackboard" 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 /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">def</span> toJSON<span style="color: #66cc66;">&#40;</span> obj <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span> obj <span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> obj <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #aaaadd; font-weight: bold;">Map</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">&quot;{&quot;</span> <span style="color: #66cc66;">+</span> obj.<span style="color: #006600;">keySet</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #663399;">inject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> accu, k <span style="color: #66cc66;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>accu.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">?</span> <span style="color: #ff0000;">&quot;&quot;</span>: <span style="color: #ff0000;">&quot;${accu},<span style="color: #000099; font-weight: bold;">\\</span>n&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;'${k}': ${toJSON(obj[k])}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>n}&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> obj <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #aaaadd; font-weight: bold;">List</span> <span style="color: #66cc66;">||</span> obj <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #aaaadd; font-weight: bold;">Set</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">&quot;[&quot;</span> <span style="color: #66cc66;">+</span> obj.<span style="color: #663399;">inject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> accu, item <span style="color: #66cc66;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#40;</span>accu.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">?</span> <span style="color: #ff0000;">&quot;&quot;</span>: <span style="color: #ff0000;">&quot;${accu},<span style="color: #000099; font-weight: bold;">\\</span>n&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toJSON<span style="color: #66cc66;">&#40;</span>item<span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">&quot;]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #ff0000;">&quot;'${obj}'&quot;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2006/09/getting-groovy-with-json/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>svn diff when line endings are different</title>
		<link>http://www.iuliandogariu.com/2006/07/svn-diff-when-line-endings-are-different/</link>
		<comments>http://www.iuliandogariu.com/2006/07/svn-diff-when-line-endings-are-different/#comments</comments>
		<pubDate>Wed, 26 Jul 2006 16:11:15 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=54</guid>
		<description><![CDATA[If you&#8217;ve ever worked in mixed-OS environments, you surely ran across this very annoying problem:
A colleague of yours made a slight change to a file and committed it from his Windows computer. You however have modified that file too, on your Linux workstation. It so happens that the file in the repository and the file [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever worked in mixed-OS environments, you surely ran across this very annoying problem:</p>
<p>A colleague of yours made a slight change to a file and committed it from his Windows computer. You however have modified that file too, on your Linux workstation. It so happens that the file in the repository and the file in your working copy have different line endings. Imagine the &#8220;pleasure&#8221; of doing a merge now <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There is hope, though. You can do a SVN diff without taking line endings into consideration, by doing this:</p>
<div class="codecolorer-container text blackboard" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">svn diff --diff-cmd /usr/bin/diff -x &quot;-u --strip-trailing-cr&quot; yourfilename</div></td></tr></tbody></table></div>
<p>This of course assume you have the diff utility installed in /usr/bin. For more about what svn diff can do, run <tt>svn help diff</tt>.</p>
<p>I&#8217;m now grepping the <a href="http://svnbook.red-bean.com/en/1.2/">SVNBook</a> for a way to automatically convert line endings upon commit, sort-of what CVS can do. If you know such a way, please share <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2006/07/svn-diff-when-line-endings-are-different/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scrapbook in Eclipse</title>
		<link>http://www.iuliandogariu.com/2006/06/eclipse-introductory/</link>
		<comments>http://www.iuliandogariu.com/2006/06/eclipse-introductory/#comments</comments>
		<pubDate>Sat, 24 Jun 2006 17:15:24 +0000</pubDate>
		<dc:creator>Iulian Dogariu</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jayomega.net/blog/?p=50</guid>
		<description><![CDATA[It&#8217;s never too late to read introductory books on Eclipse. More specifically, this book. You may be missing out on some pretty cool features. For example, how could I miss out on something as useful as the Scrapbook?
Essentially a Scrapbook page in Eclipse allows you to type code and execute on the fly. You don&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s never too late to read introductory books on Eclipse. More specifically, <a href="http://www.oreilly.com/catalog/eclipse/">this book</a>. You may be missing out on some pretty cool features. For example, how could I miss out on something as useful as the Scrapbook?</p>
<p>Essentially a Scrapbook page in Eclipse allows you to type code and execute on the fly. You don&#8217;t need to create a function or even a class. This is really sweet if you want to try out something quick and dirty, before incorporating it into your code. In this respect, it resembles the <a href="http://en.wikipedia.org/wiki/Read-eval-print_loop">REPL</a> of LISP or Ruby or Perl.  Plus you get most of the benefits of the Java editor, such as code completion <img src='http://www.iuliandogariu.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img src='wp-content/eclipsescrapbook.png' alt='Eclipse scrapbook shot' /></p>
<p>To create a scrapbook page in Eclipse 3.2, go to File->New->Other&#8230; then choose Java -> Run/Debug -> Scrapbook page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iuliandogariu.com/2006/06/eclipse-introductory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
