<?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>of bits and bytes &#187; .NET</title>
	<atom:link href="http://blog.rolandbaer.ch/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rolandbaer.ch</link>
	<description>Der normale Wahnsinn in der Softwarewelt - The ordinary madness in the world of software.</description>
	<lastBuildDate>Sun, 05 Feb 2012 16:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rekursiv vs. Iterativ</title>
		<link>http://blog.rolandbaer.ch/2012/01/29/rekursiv-vs-iterativ/</link>
		<comments>http://blog.rolandbaer.ch/2012/01/29/rekursiv-vs-iterativ/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 17:16:21 +0000</pubDate>
		<dc:creator>Roland Bär</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Deutsch]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Factorial]]></category>
		<category><![CDATA[Fakultät]]></category>
		<category><![CDATA[Mathematik]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Stack Overflow]]></category>

		<guid isPermaLink="false">http://blog.rolandbaer.ch/?p=453</guid>
		<description><![CDATA[Rekursiv oder Iterativ, was ist für den Computer "einfacher zu verstehen"?]]></description>
			<content:encoded><![CDATA[<p>In der <a href="http://www.dotnetpro.de/">dotnetpro</a> <a href="http://www.dotnetpro.de/articles/articlearchive1763.aspx">8/2011</a> hat <a href="http://www.ralfw.de/">Ralp Westphal</a> im Artikel <a href="http://www.dotnetpro.de/articles/onlinearticle3802.aspx">&#8220;Aus Baum mach Fluss&#8221;</a> zum Einstieg die <a href="http://de.wikipedia.org/wiki/Fakult%C3%A4t_%28Mathematik%29" title="Fakultät (Mathematik)">Fakultät</a>sberechnung in der rekursiven und in der iterativen Variante gezeigt. Seiner Meinung nach ist die iterative Variante einfacher zu verstehen, besonders für nicht-Mathematiker.<br />
Ich fragte mich dann, welche Variante ist für den Computer einfacher zu verstehen, d.h. welche Variante ist performanter? Oder ist es egal, optimiert der Compiler schon so weit, dass beide Varianten in etwa gleich schnell sind?</p>
<p>Ich habe ein <a href='http://blog.rolandbaer.ch/wp-content/uploads/2012/01/factorial.zip'>kleines Programm</a> geschrieben, dass die Fakultät für verschiedene Werte mehrmals berechnet, um messbare Werte zu erhalten.<br />
Hier die Resultate:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Factorial recursive and iterative<br />
---------------------------------<br />
<br />
10!<br />
Recursive: 00:00:00.0390023<br />
Iterative: 00:00:00.0220012<br />
<br />
100!<br />
Recursive: 00:00:00.2940168<br />
Iterative: 00:00:00.1720099<br />
<br />
1000!<br />
Recursive: 00:00:02.5131437<br />
Iterative: 00:00:01.0270588<br />
<br />
10000!<br />
Recursive: 00:00:25.0624335<br />
Iterative: 00:00:09.4535407</div></div>
<p>Die rekursive Variante braucht also etwa 2.5 mal so lang wie die iterative. Und bei grossen Fakultäten kommt noch ein weiteres Problem hinzu: Es wird eine StackOverflowException geworfen, da jeder Rekursionsschritt einen Funktionsaufruf zur Folge hat, der einen Teil des Stacks beansprucht.</p>
<p><strong>Fazit:</strong><br />
Der iterative Ansatz ist (mindestens in diesem Fall) auch für den Computer &#8220;einfacher zu verstehen&#8221;. Neben der besseren Performance ist aber auch die gebannte Gefahr des Stack Overflows ein wichtiger Grund, die iterative Varinate vorzuziehen.</p>
<p><a href='http://blog.rolandbaer.ch/wp-content/uploads/2012/01/factorial.zip'>Factorial Source Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rolandbaer.ch/2012/01/29/rekursiv-vs-iterativ/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Slippery When Wet #5: The Process object or Optimization? don&#8217;t do it!</title>
		<link>http://blog.rolandbaer.ch/2011/11/12/slippery-when-wet-5-the-process-object/</link>
		<comments>http://blog.rolandbaer.ch/2011/11/12/slippery-when-wet-5-the-process-object/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 10:40:07 +0000</pubDate>
		<dc:creator>Roland Bär</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Pitfall]]></category>
		<category><![CDATA[Slippery When Wet]]></category>
		<category><![CDATA[SWW]]></category>

		<guid isPermaLink="false">http://blog.rolandbaer.ch/?p=392</guid>
		<description><![CDATA[I proudly present to you the fifth in a infinite number of posts of “Slippery When Wet.” In these posts I show you a little bastard I stumbled on. To get the memory usage information you can use the System.Diagnostics.Process class. As I wantet to check the memory usage regularly I kept the reference to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.rolandbaer.ch/wp-content/uploads/2008/10/slipperywhenwet.gif"><img src="http://blog.rolandbaer.ch/wp-content/uploads/2008/10/slipperywhenwet-216x300.gif" alt="Slippery When Wet" title="Slippery When Wet" width="216" height="300" class="alignright size-medium wp-image-61" /></a>I proudly present to you the fifth in a infinite number of posts of “Slippery When Wet.” In these posts I show you a little bastard I stumbled on.</p>
<p>To get the memory usage information you can use the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx">System.Diagnostics.Process</a> class. As I wantet to check the memory usage regularly I kept the reference to the Process object in my class. But the value never changed anymore&#8230; Then I tried to get the Process object every time i needed the current memory size &ndash; and it worked. </p>
<p>So I read the documentation a little more carefully and got to this part:</p>
<blockquote><p>
The process component obtains information about a group of properties all at once. After the Process component has obtained information about one member of any group, it will cache the values for the other properties in that group and not obtain new information about the other members of the group until you call the Refresh method. Therefore, a property value is not guaranteed to be any newer than the last call to the Refresh method. The group breakdowns are operating-system dependent.</p></blockquote>
<p>So I changed my code again to not get the Process every time I wanted the current memory size but call the Refresh method.</p>
<p>And what did we learn from this episode? </p>
<p><a href="http://en.wikipedia.org/wiki/Michael_A._Jackson">Michael A. Jackson</a> (&#8220;<a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29#Quotes">The First Rule of Program Optimization: Don&#8217;t do it (&#8230;)</a>&#8220;) and <a href="http://en.wikipedia.org/wiki/Donald_Knuth">Donald Knuth</a> (&#8220;<a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%29#Quotes">(&#8230;) premature optimization is the root of all evil (&#8230;)</a>&#8220;) are right. Don&#8217;t do optimization, especially not if you don&#8217;t really know what you are doing&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rolandbaer.ch/2011/11/12/slippery-when-wet-5-the-process-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Reflectors Erben</title>
		<link>http://blog.rolandbaer.ch/2011/05/18/net-reflectors-erben/</link>
		<comments>http://blog.rolandbaer.ch/2011/05/18/net-reflectors-erben/#comments</comments>
		<pubDate>Wed, 18 May 2011 20:57:15 +0000</pubDate>
		<dc:creator>Roland Bär</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Deutsch]]></category>
		<category><![CDATA[ILSpy]]></category>
		<category><![CDATA[Reflector]]></category>
		<category><![CDATA[SharpDevelop]]></category>

		<guid isPermaLink="false">http://blog.rolandbaer.ch/?p=277</guid>
		<description><![CDATA[Nachdem redgate Anfangs Februar Ankündigte, dass der .NET Reflector kostenpflichtig wird, haben sich mehrere Nachfolger empfohlen: Als erstes kündigte das Team von #develop das Tool ILSpy an. Danach folgte Telerik mit JustDecompile. JetBrains, welche sich auch für &#8230; verantwortlich zeichnen, kündigten dann auch noch einen Erben an, das Tool dotPeek. Redgate kündigte währenddessen an, dass [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem <a href="http://www.red-gate.com/">redgate</a> Anfangs Februar Ankündigte, dass der <a href="http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1">.NET Reflector kostenpflichtig</a> wird, haben sich mehrere Nachfolger empfohlen:</p>
<p>Als erstes kündigte das Team von <a href="http://www.sharpdevelop.net/">#develop</a> das Tool <a href="http://wiki.sharpdevelop.net/ILSpy.ashx">ILSpy</a> an.</p>
<p>Danach folgte <a href="http://www.telerik.com/">Telerik</a> mit <a href="http://www.telerik.com/products/decompiling.aspx">JustDecompile</a>.</p>
<p>JetBrains, welche sich auch für &#8230; verantwortlich zeichnen, kündigten dann auch noch einen Erben an, das Tool <a href="http://www.jetbrains.com/decompiler/">dotPeek</a>.</p>
<p>Redgate kündigte währenddessen an, dass es weiterhin eine <a href="http://www.reflector.net/2011/04/why-we-reversed-some-of-our-reflector-decision/">kostenlose Version von .NET Reflector</a> geben wird. Es ist in diesem Bereich also noch einiges in Bewegung&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rolandbaer.ch/2011/05/18/net-reflectors-erben/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auswahl der zu benutzenden Framework-Version</title>
		<link>http://blog.rolandbaer.ch/2008/11/12/auswahl-der-zu-benutzenden-framework-version/</link>
		<comments>http://blog.rolandbaer.ch/2008/11/12/auswahl-der-zu-benutzenden-framework-version/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 22:48:52 +0000</pubDate>
		<dc:creator>Roland Bär</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Deutsch]]></category>

		<guid isPermaLink="false">http://blog.rolandbaer.ch/?p=76</guid>
		<description><![CDATA[Um eine .net-Applikation mit einer bestimmten Framework-Version auszuführen, kann diese im App.Conifg-File angegeben werden. Mit folgendem Beispiel wird die Anwendung mit dem Framework 1.1 ausgeführt, wenn man den Kommentar um das andere supportedRuntime-Tag setzt, wird das Framework 2.0 verwenden. &#60; ?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;&#62; &#60;configuration&#62; &#160; &#160;&#60;startup&#62; &#160; &#160; &#160; &#60;supportedruntime version=&#34;v1.1.4322&#34;/&#62; &#60;!-- &#160; &#160; &#160;&#60;supportedRuntime [...]]]></description>
			<content:encoded><![CDATA[<p>Um eine .net-Applikation mit einer bestimmten Framework-Version auszuführen, kann diese im App.Conifg-File angegeben werden. Mit folgendem Beispiel wird die Anwendung mit dem Framework 1.1 ausgeführt, wenn man den Kommentar um das andere supportedRuntime-Tag setzt, wird das Framework 2.0 verwenden.</p>
<div class="codecolorer-container xml geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<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;startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;supportedruntime</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;v1.1.4322&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #808080; font-style: italic;">&lt;!-- &nbsp; &nbsp; &nbsp;&lt;supportedRuntime version=&quot;v2.0.50727&quot;/&gt;--&gt;</span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Die Datei muss dabei dem Dateinamen der Anwendung mit angehängtem .config entsprechen, z.B. für die Anwendung &#8220;MyApp.exe&#8221; heisst die Datei &#8220;MyApp.exe.config&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rolandbaer.ch/2008/11/12/auswahl-der-zu-benutzenden-framework-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slippery When Wet #2: SCOPE_IDENTITY and SqlDataReader</title>
		<link>http://blog.rolandbaer.ch/2008/10/25/slippery-when-wet-2-scope-identity-sqldatareader/</link>
		<comments>http://blog.rolandbaer.ch/2008/10/25/slippery-when-wet-2-scope-identity-sqldatareader/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 21:08:23 +0000</pubDate>
		<dc:creator>Roland Bär</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Slippery When Wet]]></category>
		<category><![CDATA[SWW]]></category>

		<guid isPermaLink="false">http://blog.rolandbaer.ch/?p=65</guid>
		<description><![CDATA[I proudly present to you the second in a infinite number of posts of “Slippery When Wet.” In these posts I show you a little bastard I stubled on. Imagine you have a database table with a cloumn id of the data type integer that has set the IDENTITY. You use a stored procedure to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.rolandbaer.ch/wp-content/uploads/2008/10/slipperywhenwet.gif"><img src="http://blog.rolandbaer.ch/wp-content/uploads/2008/10/slipperywhenwet-216x300.gif" alt="" title="Slippery When Wet" width="216" height="300" class="alignright size-medium wp-image-61" /></a>I proudly present to you the second in a infinite number of posts of “Slippery When Wet.” In these posts I show you a little bastard I stubled on.</p>
<p>Imagine you have a database table with a cloumn id of the data type integer that has set the IDENTITY. You use a stored procedure to insert a new entry into this table. Inside this stored procedure you use the SCOPE_IDENTITY() function to get the identifier created for this row. With RETURN SCOPE_IDENTITY() you give the identity to the caller.</p>
<p>You call this stored procedure from a SqlComand with ExecuteReader() that returns you an SqlDataReader object.</p>
<p>From this SqlDataReader you read now the identifier with GetInt32().</p>
<p><strong>Wrong ! </strong></p>
<p>This will give you an InvalidCastException. SCOPE_IDENTITY()&#8217;s return type is numeric, although your identifier column is an integer. SqlDataReader&#8217;s GetXY functions do not convert the data and throw the exception when the data is not already of the right type.</p>
<h3>The first solution</h3>
<p>You can read the value with GetDecimal() and cast the value to an int:</p>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">int</span> identifier <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>reader<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDecimal</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<h3>The second solution</h3>
<p>You cast the identifier inside the stored procedure und return it already as an integer:</p>
<div class="codecolorer-container sql geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>SCOPE_IDENTITY<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#41;</span></div></div>
<p>Whatever solution you choose, take care that you use always the same inside your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rolandbaer.ch/2008/10/25/slippery-when-wet-2-scope-identity-sqldatareader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

