<?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>Erata.NET</title>
	<atom:link href="http://www.erata.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erata.net</link>
	<description>If we don't have the solution you have the wrong problem</description>
	<lastBuildDate>Sat, 19 Jun 2010 08:02:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Context Matters</title>
		<link>http://www.erata.net/programming/context-matters/</link>
		<comments>http://www.erata.net/programming/context-matters/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 08:02:52 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.erata.net/programming/context-matters/</guid>
		<description><![CDATA[The next paragraph made me remember of a lot of hours of discussions with various developers: If you’re arguing with me that NHibernate is the wrong tool because you’re writing reporting applications, just say “I write reporting applications.”&#160; And when I say “I think NHibernate is the best tool for persisting domain models,” I should [...]]]></description>
			<content:encoded><![CDATA[<p>The next paragraph made me remember of a lot of hours of discussions with various developers:</p>
<blockquote><p>If you’re arguing with me that NHibernate is the wrong tool because you’re writing reporting applications, just say “I write reporting applications.”&#160; And when I say “I think NHibernate is the best tool for persisting domain models,” I should probably talk about that specific context.&#160; And definitely, when you say “Linq to Sql rocks!” you better follow that up with “for applications with simplistic domain models.” ( source: <a title="Context Matters" href="http://codebetter.com/blogs/jeremy.miller/archive/2010/01/24/a-train-of-thought-january-2010-edition.aspx">Context Matters</a>)</p>
</blockquote>
<p>If more developers would think like this we would probably have better tools with better acceptance in a lot less time.</p>
<div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;">
<p><script type="text/javascript">
tweetmeme_url = 'http://www.erata.net/programming/context-matters/';
tweetmeme_source = 'etishor';
</script><br />
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/programming/context-matters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress upgrade to 3.0</title>
		<link>http://www.erata.net/news/wordpress-upgrade-to-3-0/</link>
		<comments>http://www.erata.net/news/wordpress-upgrade-to-3-0/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 08:06:10 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=152</guid>
		<description><![CDATA[.. And again WordPress upgrade worked like a charm&#8230; on click db backup &#8230; one click upgrade from 2.X to 3.0. All the plugins seem to work fine but if you see anything wrong please drop me a line.]]></description>
			<content:encoded><![CDATA[<p>.. And again WordPress upgrade worked like a charm&#8230; on click db backup &#8230; one click upgrade from 2.X to 3.0. All the plugins seem to work fine but if you see anything wrong please drop me a line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/news/wordpress-upgrade-to-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Console2 The missing tool for windows</title>
		<link>http://www.erata.net/windows/console2-the-missing-tool-for-windows/</link>
		<comments>http://www.erata.net/windows/console2-the-missing-tool-for-windows/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 06:47:17 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[windows]]></category>
		<category><![CDATA[Console]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=148</guid>
		<description><![CDATA[I finally found it!!! It&#8217;s been years since i was looking for it and now thanks to Rob Conery&#8217;s post i&#8217;ve found Console2. Get it here]]></description>
			<content:encoded><![CDATA[<p>I finally found it!!! It&#8217;s been years since i was looking for it and now thanks to <a href="http://blog.wekeroad.com/2010/04/29/visual-tooling-will-make-you-go-blind">Rob Conery&#8217;s post</a> i&#8217;ve found Console2.
</p>
<p>Get it <a href="http://sourceforge.net/projects/console/">here</a></p>
<p><img src="http://sourceforge.net/dbimage.php?id=81523" alt="Console2" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/windows/console2-the-missing-tool-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NServiceBus with NHibernate and MySQL</title>
		<link>http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/</link>
		<comments>http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 10:59:26 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[distributed]]></category>
		<category><![CDATA[fault tolerant]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[MSDTC]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nhibernate]]></category>
		<category><![CDATA[nservicebus]]></category>
		<category><![CDATA[transactions]]></category>

		<guid isPermaLink="false">http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/</guid>
		<description><![CDATA[In the last project I have been working i finally got a chance to design and implement a solution based on NServiceBus and NHibernate, two tools I’ve been watching for a while but never got a chance to play with in more than sample applications. For some external reasons I&#8217;ve been forced to use MySQL [...]]]></description>
			<content:encoded><![CDATA[<p>In the last project I have been working i finally got a chance to design and implement a solution based on <a title="NServiceBus" href="http://nservicebus.com/">NServiceBus</a> and <a title="NHibernate" href="http://nhforge.org/">NHibernate</a>, two tools I’ve been watching for a while but never got a chance to play with in more than sample applications. For some external reasons I&#8217;ve been forced to use <a href="http://www.mysql.com/">MySQL</a> as a database server in this project.</p>
</p>
<p> <span id="more-125"></span>
</p>
<p>So basically I’m using <a title="NServiceBus" href="http://nservicebus.com/">NServiceBus</a> to provide reliable communication between the involved components and NHibernate to do the persistence of the domain objects used by the components. Up to this point the hole design of the solution looks good, with minimal effort i have reliable, fault tolerant services that are ready to do their job.</p>
<p>Now i start implementing the details and get to the point where MySQL comes into play. I must say, it has surprised me… both ways.</p>
<p>The good thing is that after careful tuning, where my previous UNIX experience had a very important role, the database is able to handle the amounts of data that i plan to throw at it. Also it surprised me that some pretty complex queries run a lot faster than expected.</p>
<p>Then the bad things started to show up. The hardest to debug was that updating an index column from multiple parallel transactions causes deadlocks witch cause transactions to be aborted. Of course this only happens at high loads. It was not hard to avoid this after i found out what the problem was … but still after this i had a feeling of working with something that might not be as reliable as expected.</p>
<p>After that the <a title="MySQL .NET connector" href="http://dev.mysql.com/downloads/connector/net/">MySQL .NET connector</a> dropped the bomb on me: <a title="Distributed Transactions bug" href="http://bugs.mysql.com/bug.php?id=37283">Distributed Transactions are not supported</a>. Ok, they are not supported but why the hell does the connector throws an exception when used in a distributed transaction? I can understand that i can’t rely on the MySQL transaction being enlisted in the Distributed Transaction (DT) and that i have to handle that myself but not being able to use the connector AT ALL under a DT was unexpected. At this point i see only one solution: <a href="http://bazaar.launchpad.net/~mysql-clr-team/connectornet/6.2/files">grab the source</a> for the connector and modify the part that checks if a DT is present and just ignore it. Turns out this was very easy to do. If anyone is interested in this change in the connector i can provide more details.</p>
<p>Now i need to find a way of having a <a href="http://nhforge.org">NHibernate</a> ISession and a ITransaction per <a title="NServiceBus" href="http://nservicebus.com/">NServiceBus</a> message handler.</p>
<p>The first approach was something similar to what <a title="Andreas Öhlund - Nhibernate Session Management" href="http://andreasohlund.blogspot.com/2010/02/nhibernate-session-management-in.html">Andreas Öhlund describes in this blog post</a>. The only problem is that IMessageModule implementations in NServiceBus 2.0 are singletons and that was a problem because i need to store the ITransaction to commit or rollback at the end of the message handler. If in the next version of the NServiceBus there will be a way to have some message handler “wrapper” that it could work.</p>
<p>My solution was to use a base abstract class for the massage handlers. So instead of just implementing IMessageHandler&lt;T&gt; now i derive from this base class. The code below should speak for itself:</p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// Base class for message handlers.</span>
<span class="rem">/// Manages the unit of work required for handling the message.</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> MessageHandler&lt;T&gt; : IMessageHandler&lt;T&gt;
          <span class="kwrd">where</span> T : IMessage
{
    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// The injected unit of work implementation.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> IUnitOfWork unitOfWork;

    <span class="kwrd">public</span> MessageHandler(IUnitOfWork unitOfWork)
    {
        <span class="kwrd">this</span>.unitOfWork = unitOfWork;
    }

    <span class="rem">/// &lt;summary&gt;</span>
    <span class="rem">/// Concrete handlers must implement this method.</span>
    <span class="rem">/// &lt;/summary&gt;</span>
    <span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">void</span> HandleMessage(T message);

    <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(T message)
    {
        <span class="kwrd">try</span>
        {
            HandleMessage(message);
            unitOfWork.Complete();
        }
        <span class="kwrd">catch</span>
        {
            unitOfWork.Abort();
            <span class="kwrd">throw</span>;
        }
        <span class="kwrd">finally</span>
        {
            unitOfWork.Dispose();
        }
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The implementation for the IUnitOfWork is in this case very simple, providing only the creation of the session and the transaction and the required operations. Since the unit of work is created per handler and the handlers don’t use other threads to do the work I don’t need to worry about making it thread safe.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> MessageUnitOfWork: IUnitOfWork
{
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> ISessionFactory factory;
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> ITransaction transaction;
    <span class="kwrd">private</span> <span class="kwrd">readonly</span> ISession session;

    <span class="kwrd">public</span> MessageUnitOfWork(ISessionFactory factory)
    {
        <span class="kwrd">this</span>.factory = factory;
        session = factory.OpenSession();
        CurrentSessionContext.Bind(session);
        transaction = session.BeginTransaction();
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Complete()
    {
        transaction.Commit();
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Abort()
    {
        transaction.Rollback();
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()
    {
        transaction.Dispose();
        CurrentSessionContext.Unbind(factory);
        session.Dispose();
        GC.SuppressFinalize(<span class="kwrd">this</span>);
    }
}</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>There is still one small problem. If the handler finishes it’s work without and exception and the mysql transaction is committed BUT an exception is thrown by the bus when committing the distributed transaction the MySQL transaction is not rolled back. But i realized that this only means that the same message might be sent again to the handler and that the handlers in general should handle this logical case since whoever sent the message is free to send it multiple times.</p>
<p>Since I’ve got this solution working it has handled a few millions of messages and there have been crashes and transaction that got rolled back occasionally but after all the system is designed to be fault tolerant and it has proven it is. Also in all the cases the database remained in a consistent state, witch in the beginning i was not sure it will.</p>
<p>In the end i would like to thank the <a title="NServiceBus Community" href="http://nservicebus.com/Community.aspx">NServiceBus</a> team ( mainly <a title="Udi Dahan" href="http://www.udidahan.com/">Udi Dahan</a> and <a title="Andreas Öhlund blog" href="http://andreasohlund.blogspot.com">Andreas Öhlund</a> ) witch was very responsive and helpful on the support mailing list. I can only hope to find the time to contribute a few ideas to the next release of NSB. Also i would like to thank the <a href="http://nhforge.org">NHibernate</a> team for the great product they created ( can’t wait for the 3.0 ).</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:86d03807-816d-4444-8f20-f36e40b52510" class="wlWriterSmartContent"><a href="http://www.dotnetkicks.com/kick/?url=http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
<div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;">
<p><script type="text/javascript">
tweetmeme_url = 'http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/';
tweetmeme_source = 'etishor';
</script><br />
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/net/nservicebus-with-nhibernate-and-mysql/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Testing Windows Live Writer</title>
		<link>http://www.erata.net/news/testing-windows-live-writer/</link>
		<comments>http://www.erata.net/news/testing-windows-live-writer/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 11:51:17 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[blog tool]]></category>
		<category><![CDATA[live writer]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/news/testing-windows-live-writer/</guid>
		<description><![CDATA[It’s not that writing posts in WordPress is hard, but i just have a feeling that Live Writer might make me write more often . Writing these first lines seems to be a pleasant experience so far. And i would really like to publish some stuff about things that i have been working with and [...]]]></description>
			<content:encoded><![CDATA[<p>It’s not that writing posts in WordPress is hard, but i just have a feeling that Live Writer might make me write more often <img src='http://www.erata.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . Writing these first lines seems to be a pleasant experience so far. And i would really like to publish some stuff about things that i have been working with and that i found to be quite interesting … <a href="http://www.nservicebus.com">NServiceBus</a> , <a href="http://nhforge.org/Default.aspx">NHibernate</a> and other goodies … will see how it goes.</p>
<p>Code snippet test</p>
<div class="csharpcode">
<pre><span class="lnum">   1:  </span><span class="rem">/// &lt;summary&gt;</span></pre>
<pre><span class="lnum">   2:  </span><span class="rem">/// Execute action &lt;paramref name=&quot;numberOfTimes&quot;/&gt; times</span></pre>
<pre><span class="lnum">   3:  </span><span class="rem">/// &lt;/summary&gt;</span></pre>
<pre><span class="lnum">   4:  </span><span class="rem">/// &lt;param name=&quot;numberOfTimes&quot;&gt;Number of times to execute action&lt;/param&gt;</span></pre>
<pre><span class="lnum">   5:  </span><span class="rem">/// &lt;param name=&quot;action&quot;&gt;Action to execute&lt;/param&gt;</span></pre>
<pre><span class="lnum">   6:  </span><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> Times(<span class="kwrd">this</span> <span class="kwrd">int</span> numberOfTimes, Action&lt;<span class="kwrd">int</span>&gt; action)</pre>
<pre><span class="lnum">   7:  </span>{</pre>
<pre><span class="lnum">   8:  </span>      Check.NotNull(action, <span class="str">&quot;action&quot;</span>);</pre>
<pre><span class="lnum">   9:  </span>      <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; numberOfTimes; i++)</pre>
<pre><span class="lnum">  10:  </span>          action(i);</pre>
<pre><span class="lnum">  11:  </span>}</pre>
<pre><span class="lnum">  12:  </span>&#160;</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<div class="wlWriterHeaderFooter" style="margin:0px; padding:0px 0px 0px 0px;">
<p><script type="text/javascript">
tweetmeme_url = 'http://www.erata.net/news/testing-windows-live-writer/';
tweetmeme_source = 'etishor';
</script><br />
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/news/testing-windows-live-writer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress upgrade to 2.9</title>
		<link>http://www.erata.net/news/wordpress-upgrade-to-2-9/</link>
		<comments>http://www.erata.net/news/wordpress-upgrade-to-2-9/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 10:03:01 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=113</guid>
		<description><![CDATA[Finaly wordpress 2.9 is out. As usual the upgrade went smoothly without any problems. Also there seems to be no compatibility issues with the plugins, at least the ones i have installed. I have to admit, i&#8217;m not a big fan of php, and php apps in general, but i admire the great work the [...]]]></description>
			<content:encoded><![CDATA[<p>Finaly <a href="http://wordpress.org/development/2009/12/wordpress-2-9/" title="Wordpress 2.9 is Out">wordpress 2.9 is out</a>. As usual the upgrade went smoothly without any problems. Also there seems to be no compatibility issues with the plugins, at least the ones i have installed. </p>
<p>I have to admit, i&#8217;m not a big fan of php, and php apps in general, but i admire the great work the wordpress team does. I haven&#8217;t tried any .net based blog app but i see no reason to at the moment. </p>
<p>Enjoy, and if you see any issue with this blog, please drop me a line.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/news/wordpress-upgrade-to-2-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# HTTP Request</title>
		<link>http://www.erata.net/net/csharp-http-request/</link>
		<comments>http://www.erata.net/net/csharp-http-request/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 10:05:06 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[qt]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[synchronous]]></category>
		<category><![CDATA[webrequest]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=108</guid>
		<description><![CDATA[A few years ago I&#8217;ve written an article on how to perform a synchronous HTTP request using Qt 4.2. I I&#8217;ve seen this article today and since now I&#8217;m mostly working with C# i was wandering how fast can i do the same thing in c#. After very few minutes I&#8217;ve managed to came up [...]]]></description>
			<content:encoded><![CDATA[<p>A few years ago I&#8217;ve written an article on <a href="http://www.erata.net/qt-boost/synchronous-http-request/">how to perform a synchronous HTTP</a> request using Qt 4.2. I I&#8217;ve seen this article today and since now I&#8217;m mostly working with C# i was wandering how fast can i do the same thing in c#. After very few minutes I&#8217;ve managed to came up with this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">using</span> <span class="kw5">System</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">using</span> <span class="kw5">System</span>.<span class="me1">Net</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">using</span> <span class="kw5">System</span>.<span class="me1">IO</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">class</span> Program</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">static</span> <span class="kw1">void</span> Main<span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; WebRequest request = HttpWebRequest.<span class="me1">Create</span><span class="br0">&#40;</span><span class="st0">&quot;http://www.google.com&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; WebResponse response = request.<span class="me1">GetResponse</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">using</span><span class="br0">&#40;</span>StreamReader reader = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StreamReader<span class="br0">&#40;</span>response.<span class="me1">GetResponseStream</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">WriteLine</span><span class="br0">&#40;</span>reader.<span class="me1">ReadToEnd</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span class="me1">ReadKey</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>And of course the <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest_members.aspx">WebReqest </a> class allows you to specify all the properties you would ever need for any request, and also allows you to perform request in an asynchronous maner. Now i don&#8217;t think you can be more expressive than this. I like qt a lot&#8230; but i love c# now. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/net/csharp-http-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Tips and Tricks</title>
		<link>http://www.erata.net/net/net-tips-and-tricks/</link>
		<comments>http://www.erata.net/net/net-tips-and-tricks/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 12:13:14 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=103</guid>
		<description><![CDATA[I would like to share a very interesting blog with .net tips and tricks: http://kossovsky.net/]]></description>
			<content:encoded><![CDATA[<p>I would like to share a very interesting blog with .net tips and tricks:</p>
<p><a href="http://kossovsky.net/">http://kossovsky.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/net/net-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few things from C++ that i miss in C#</title>
		<link>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/</link>
		<comments>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 10:41:31 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[const correctness]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[deterministic destruction]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[paradigms]]></category>
		<category><![CDATA[reference type]]></category>
		<category><![CDATA[static initialization]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[value type]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=90</guid>
		<description><![CDATA[The last 6-7 months i&#8217;ve been working mostly with C# and to be honest I&#8217;ve grown found to it. It has really nice features like lambda expressions,   auto properties, extension methods, LINQ witch can really speed up things in terms development time. Still &#8230; there are some things from C++ that i now miss: Templates [...]]]></description>
			<content:encoded><![CDATA[<p>The last 6-7 months i&#8217;ve been working mostly with C# and to be honest I&#8217;ve grown found to it. It has really nice features like lambda expressions,   auto properties, extension methods, LINQ witch can really speed up things in terms development time.</p>
<p>Still &#8230; there are some things from C++ that i now miss: Templates ( as in true generics ) , const correctness, deterministic destruction, static initialization and most of all the control over what is a value and what is a reference.</p>
<h3>Generics ( Templates )</h3>
<p>Yes, C# has generics witch give you a level of freedom and ability to write generic code but they are nothing compared to the power of c++ templates. In C++ templates are compiled when instantiated and you don&#8217;t need to specify any constraints on the  generic type and as long as the instantiated type is syntactically correct your code will compile. There are ways to define concepts witch can impose requirements on the types but the concepts are also verified when the template is instantiated. Also C# does not allow specialization or partial specialization of generic types.</p>
<h3>Const Correctness</h3>
<p>There are a lot of articles on the web about why C# does not implement const correctness. In the end you learn to leave without it but its a nice thing to have and as long as you use it consistently it can help prevent a lot of bugs mostly design bugs. I guess that there are ways in C# to prevent the bugs that const correctness prevents  ( immutable objects, ReadOnly interfaces ) but they are harder to impose on a team of developers.</p>
<h3>Deterministic Destruction</h3>
<p>I&#8217;m quite sure that I only miss this feature because i come with a C++ background. You can easily have deterministic destruction in C# by using IDisposable and using(&#8230;) features, still after years of C++ i kinda like to know when an object gets destructed.</p>
<h3>Static Initialization</h3>
<p>To be honest I don&#8217;t miss this feature too much. The only thing i find it useful for is implementing the factory pattern where objects register themselves in the factory using static initialization. The downside of this is that it can relay get messy ( hint Static Initialization Fiasco )</p>
<h3>Control over what is a value and what is a reference</h3>
<p>Now this i miss the most. I have to admit it I like pointers. Well i actually like smart pointers and i like being in control of what and how i pass as arguments to methods. In C# it&#8217;s written in stone: structs are values and classes are references (ok, with boxing you can have references to structs but that&#8217;s not the point ). One of the problems is that there is no way of declaring a method that accepts a CONST reference to an instance. When you pass an instance of a class to a method (you actually pass the reference to that instance) , the method has full control over the instance.  This might not be a problem when you write all the code, but in a team with developers of different skill bad things can happen. Add some multi-threading to this and things can get relay messy. Another problem is when you have a value object implemented as a struct that is holding a lot of data and you need to pass this object to a Method that only needs to read something from this object. If you pass it as a value object it will probably get copied ( i&#8217;m not sure if the compiler does not implement some copy-on-write here but i would not relay on that ) and if you pass it as a ref than the method might change the data.</p>
<p>In conclusion I like working with C# but there are some things that i hope will get better in time. Other important  &#8220;bonuses&#8221; you get with C# are the .NET Framework and Visual Studio IDE that speed up substantially the development. The major downsite witch in some cases is a showstopper: Platform Dependent. I don&#8217;t know where MONO is right now but if you develop with C# and .NET you better make sure your main target platform is Windows.</p>
<p>I would be glad to hear what others think about this.</p>
<p><!–dotnetkickit–></p>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/net/a-few-things-from-c-that-i-miss-in-c/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>The power of SUDO</title>
		<link>http://www.erata.net/jokes/the-power-of-sudo/</link>
		<comments>http://www.erata.net/jokes/the-power-of-sudo/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 07:24:25 +0000</pubDate>
		<dc:creator>eti</dc:creator>
				<category><![CDATA[Jokes]]></category>
		<category><![CDATA[joke]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=85</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div id="attachment_84" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.erata.net/wp-content/uploads/2009/06/sandwich.png"><img class="size-medium wp-image-84" title="sandwich" src="http://www.erata.net/wp-content/uploads/2009/06/sandwich-300x249.png" alt="Sandwich" width="300" height="249" /></a><p class="wp-caption-text">Sandwich</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/jokes/the-power-of-sudo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
