<?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>Talkwards &#187; programming practices</title>
	<atom:link href="http://www.talkwards.com/tag/programming-practices/feed" rel="self" type="application/rss+xml" />
	<link>http://www.talkwards.com</link>
	<description>Advancing Talkwards...</description>
	<lastBuildDate>Sat, 03 Sep 2011 16:33:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Sun Tzu&#8217;s Art of War &#8211; Agile&#8230;</title>
		<link>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile</link>
		<comments>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile#comments</comments>
		<pubDate>Fri, 05 Jun 2009 23:00:59 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[agile programming]]></category>
		<category><![CDATA[programming practices]]></category>

		<guid isPermaLink="false">http://www.talkwards.com/?p=541</guid>
		<description><![CDATA[A quote from the Art of War that might have some baring on Agile development techniques: 31. Water shapes its course according to the nature of the ground over which it flows; the soldier works out his victory in relation to the foe whom he is facing. 32. Therefore, just as water retains no constant [...]]]></description>
			<content:encoded><![CDATA[<p>A quote from the Art of War that might have some baring on Agile development techniques:</p>
<blockquote><p>31. Water shapes its course according to the nature<br />
of the ground over which it flows; the soldier works<br />
out his victory in relation to the foe whom he is facing.</p>
<p>32. Therefore, just as water retains no constant shape,<br />
so in warfare there are no constant conditions.</p></blockquote>
<p>But then again, we all know war is agile, right?</p>
<p>Or another quote I heard (source unknown, original language Swedish):</p>
<blockquote><p>Meeting all requirements in programming is like walking on water.  It&#8217;s easy if the water and the requirements are frozen&#8230;</p></blockquote>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2009%2F06%2Fsun-tzus-art-of-war-agile&amp;title=Sun%20Tzu%26%238217%3Bs%20Art%20of%20War%20%26%238211%3B%20Agile%26%238230%3B" id="wpa2a_2"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2009/06/sun-tzus-art-of-war-agile/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterating a list, and deleting from it, Java vs .NET</title>
		<link>http://www.talkwards.com/2007/09/iterating-a-list-and-deleting-from-it-java-vs-net</link>
		<comments>http://www.talkwards.com/2007/09/iterating-a-list-and-deleting-from-it-java-vs-net#comments</comments>
		<pubDate>Tue, 04 Sep 2007 02:16:47 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming practices]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=95</guid>
		<description><![CDATA[Or how I came to realize I could live a life time without .NET and be just as happy. I&#8217;m just fresh from having tried to iterate a list&#8230; and delete items from it while iterating.  In .NET with C#. It turns out a statement like: void deleteFromList(IList&#60;X&#62; list) {      foreach (X x in [...]]]></description>
			<content:encoded><![CDATA[<p>Or how I came to realize I could live a life time without .NET and be just as happy.</p>
<p>I&#8217;m just fresh from having tried to iterate a list&#8230; and delete items from it while iterating.  In .NET with C#.</p>
<p>It turns out a statement like:</p>
<pre style="padding-left: 30px;">void deleteFromList(IList&lt;X&gt; list) {
     foreach (X x in list) {
        if (x.DeleteMe) {
            list.Remove(x);
        }
    }
}</pre>
<p>Will throw an InvalidOperationException stating you cannot perform a foreach and delete at the same time.  This is actually not that big of a surprise, or it shouldn&#8217;t be&#8230;  the same happens in Java if you delete and iterate at the same time.</p>
<p>This is how I would have done this in Java:</p>
<pre style="padding-left: 30px;">void deleteFromList(List&lt;X&gt; list) {
     Iterator&lt;X&gt; itr = list.iterator();
     while (itr.hasNext()) {
	X x = itr.next();
        if (x.DeleteMe) {
            itr.remove();
        }
    }
}</pre>
<p>It&#8217;s simple, clean and it does not throw exceptions. If you believe the code may be run asynchronously, slap on a &#8220;synchronized&#8221; and you&#8217;re home safe.</p>
<p>So, how to do this with .NET?  Well, you can&#8217;t use Enumerators (which are the .NET &#8220;equivalent&#8221; of iterators), they don&#8217;t have a remove method.  Further worse, if you are unlucky enough to run version 1.1 your only option seems to be some unholy concoction like:</p>
<pre style="padding-left: 30px;">void deleteFromList(IList&lt;X&gt; list) {
    IList&lt;X&gt; toBeDeleted = new List&lt;X&gt;();

    foreach (X x in list) {
        if (x.DeleteMe) {
            toBeDeleted.Add(x);
        }
    }

    foreach (X x in toBeDeleted) {
        list.Remove(x);
    }
}</pre>
<p>Don&#8217;t even start a conversation on synchronization with this mixup.  Anyway, those who are &#8220;lucky&#8221; enough to code .NET 2.0 can do something like:</p>
<pre style="padding-left: 30px;">myList.RemoveAll(delegate(X x) { return x.DeleteMe; });</pre>
<p>Now, if you&#8217;d like to base the &#8220;DeleteMe&#8221; calculation on some external paramter like input to the deleteFromList method or if you&#8217;d like to do more than just delete x you&#8217;ll have to experiment, it&#8217;s probably possible&#8230; with a solution like the double lists above perhaps?</p>
<p>Regardless.  Someone said it was old news to be a Java programmer, I can only guess because of the lower hour wastage when you program Java systems, which in turn means lower bills to the clients and finally lower wages to the programmers.</p>
<p>It costs to be on top&#8230;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2007%2F09%2Fiterating-a-list-and-deleting-from-it-java-vs-net&amp;title=Iterating%20a%20list%2C%20and%20deleting%20from%20it%2C%20Java%20vs%20.NET" id="wpa2a_4"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2007/09/iterating-a-list-and-deleting-from-it-java-vs-net/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming booleans</title>
		<link>http://www.talkwards.com/2007/07/programming-booleans</link>
		<comments>http://www.talkwards.com/2007/07/programming-booleans#comments</comments>
		<pubDate>Mon, 09 Jul 2007 02:09:48 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jcr]]></category>
		<category><![CDATA[jsr170]]></category>
		<category><![CDATA[programming practices]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=93</guid>
		<description><![CDATA[When looking at other programmer&#8217;s code I&#8217;m sometimes surprised with things like this: exportDocumentView(java.lang.String absPath, java.io.OutputStream out, boolean skipBinary, boolean noRecurse) And in such prominent frameworks as Java Content Repository as well. What&#8217;s my problem then? Double negations. In order to do exportDocumentView and get binary data and recursive export you&#8217;ll need to do: exportDocumentView(&#8220;/path/to/my/Node/&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>When looking at other programmer&#8217;s code I&#8217;m sometimes surprised with things like this:</p>
<blockquote><p>exportDocumentView(java.lang.String absPath, java.io.OutputStream out,<br />
boolean skipBinary, boolean noRecurse)</p></blockquote>
<p>And in such prominent frameworks as <a href="http://en.wikipedia.org/wiki/Content_repository_API_for_Java">Java Content Repository</a> as well.</p>
<p>What&#8217;s my problem then? Double negations. In order to do exportDocumentView and get binary data and recursive export you&#8217;ll need to do:</p>
<blockquote><p>exportDocumentView(&#8220;/path/to/my/Node/&#8221;, System.out, false, false)</p></blockquote>
<p>Sure I can handle it&#8230; but&#8230; false to opt something in? I find it rather fishy. Call me an idiot but my brain just don&#8217;t deal with that kind of stuff easily&#8230;</p>
<p>What I would have wanted instead was:</p>
<blockquote><p>exportDocumentView(java.lang.String absPath, java.io.OutputStream out,<br />
boolean includeBinary, boolean recursive)</p></blockquote>
<p>Which would have been called like:</p>
<blockquote><p>exportDocumentView(&#8220;/path/to/my/Node/&#8221;, System.out, true, true)</p></blockquote>
<p>For when we want binary data and recursive export, and like this for the case when we don&#8217;t want either or both:</p>
<blockquote><p>exportDocumentView(&#8220;/path/to/my/Node/&#8221;, System.out, false, true)<br />
exportDocumentView(&#8220;/path/to/my/Node/&#8221;, System.out, true, false)<br />
exportDocumentView(&#8220;/path/to/my/Node/&#8221;, System.out, false, false)</p></blockquote>
<p>I&#8217;m just saying.  In my world false means &#8220;no&#8221; and &#8220;no&#8221; means don&#8217;t give me something or don&#8217;t do something:</p>
<blockquote><p>&#8220;Don&#8217;t return binary data.&#8221;<br />
&#8220;Don&#8217;t recurse the tree of nodes.&#8221;</p></blockquote>
<p>To be compared with:</p>
<blockquote><p>&#8220;Don&#8217;t skip binary data.&#8221;<br />
&#8220;Don&#8217;t do no recursing.&#8221;</p></blockquote>
<p>(But you&#8217;re free to curse? <img src='http://www.talkwards.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> )</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.talkwards.com%2F2007%2F07%2Fprogramming-booleans&amp;title=Programming%20booleans" id="wpa2a_6"><img src="http://www.talkwards.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.talkwards.com/2007/07/programming-booleans/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

