<?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; .net</title>
	<atom:link href="http://www.talkwards.com/tag/net/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>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_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/2007/09/iterating-a-list-and-deleting-from-it-java-vs-net/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GoogleBot may crash .NET 2.0 sites</title>
		<link>http://www.talkwards.com/2007/08/googlebot-may-crash-net-20-sites</link>
		<comments>http://www.talkwards.com/2007/08/googlebot-may-crash-net-20-sites#comments</comments>
		<pubDate>Fri, 17 Aug 2007 02:12:29 +0000</pubDate>
		<dc:creator>Hoakz</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.hoakz.com/blog/?p=27</guid>
		<description><![CDATA[ASP.NET 2.0 apparently has a vulnerability when doing URL rewriting, making it possible for Googlebot (and possibly other search engine bots as well?) to crash a .NET 2.0 site. Read more on todotnet.com]]></description>
			<content:encoded><![CDATA[<p>ASP.NET 2.0 apparently has a vulnerability when doing URL rewriting, making it possible for Googlebot (and possibly other search engine bots as well?) to crash a .NET 2.0 site.</p>
<p><a href="http://todotnet.com/archive/0001/01/01/7472.aspx" target="_blank">Read more on todotnet.com</a></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%2F08%2Fgooglebot-may-crash-net-20-sites&amp;title=GoogleBot%20may%20crash%20.NET%202.0%20sites" 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/08/googlebot-may-crash-net-20-sites/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

