<?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>Daniel Stutzbach &#187; C#</title>
	<atom:link href="http://www.barsoom.org/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.barsoom.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 14 Jul 2010 23:19:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Scriptable Equity Calculator</title>
		<link>http://www.barsoom.org/scriptable-equity-calculator</link>
		<comments>http://www.barsoom.org/scriptable-equity-calculator#comments</comments>
		<pubDate>Thu, 24 Jun 2010 20:09:42 +0000</pubDate>
		<dc:creator>Daniel Stutzbach</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[poker]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.barsoom.org/?p=891</guid>
		<description><![CDATA[<p>For all of your programming poker players out there, yesterday I made the <a href="http://pokersleuth.com/">Poker Sleuth</a> <a href="http://pokersleuth.com/poker-equity-calculator.shtml">Equity Calculator</a> scriptable with <a href="http://pokersleuth.com/programmable-poker-calculator.shtml">bindings for C/C++, C#, and Python.</a></p>
<p>If you have easy_install or pip set up for Python, you can just do &#8220;easy_install pokersleuth&#8221;.  It requires a 32-bit version of Python for Windows.</p>
<p>As an example, <p style="font-family: serif;">Continue reading &#8220;<a href="http://www.barsoom.org/scriptable-equity-calculator">A Scriptable Equity Calculator</a>&#8221;</p>]]></description>
			<content:encoded><![CDATA[<p>For all of your programming poker players out there, yesterday I made the <a href="http://pokersleuth.com/">Poker Sleuth</a> <a href="http://pokersleuth.com/poker-equity-calculator.shtml">Equity Calculator</a> scriptable with <a href="http://pokersleuth.com/programmable-poker-calculator.shtml">bindings for C/C++, C#, and Python.</a></p>
<p>If you have easy_install or pip set up for Python, you can just do &ldquo;easy_install pokersleuth&rdquo;.  It requires a 32-bit version of Python for Windows.</p>
<p>As an example, to compute the odds of winning when you have a pair of Jacks, your opponent has the Ace and 5 of diamonds, and the board cards are the 3 of diamonds, 5 of clubs, and 9 of diamonds:</p>
<p><code>>>> import pokersleuth<br />
>>> pokersleuth.calculate_equity('3d5c9d', ('JJ', 'Ad5d')<br />
[0.48225, 0.51775]</code></p>
<p>The module can also be used directly from the command line:</p>
<p><code>C:\>python -m pokersleuth 3d5c9d JJ Ad5d<br />
[0.48225, 0.51775]</code></p>
<p>It supports up to 10 players and a quite extensive syntax for specifying hand ranges.  Accuracy is within one percentage point with at least 99.5% probability.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barsoom.org/scriptable-equity-calculator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DefaultValue Attribute as Initial Value</title>
		<link>http://www.barsoom.org/defaultvalue-attribute-initial</link>
		<comments>http://www.barsoom.org/defaultvalue-attribute-initial#comments</comments>
		<pubDate>Tue, 14 Jul 2009 22:03:24 +0000</pubDate>
		<dc:creator>Daniel Stutzbach</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.barsoom.org/?p=720</guid>
		<description><![CDATA[




<img align="right" alt="Visual Studio Properties" class="size-full wp-image-729 align-right" src="http://c0348292.cdn.cloudfiles.rackspacecloud.com/wp-content/uploads/2009/07/visual_studio_properties.png" style="width: 323px; height: 105px;" />
<p>C# lets the programming define a default value on a class property, so that GUI widgets can test the property to see if it still has the default value.  Visual Studio, for example, bolds any properties that have a non-default value, <p style="font-family: serif;">Continue reading &#8220;<a href="http://www.barsoom.org/defaultvalue-attribute-initial">DefaultValue Attribute as Initial Value</a>&#8221;</p>]]></description>
			<content:encoded><![CDATA[



<!-- -*- mode: rst -*- -->
<img align="right" alt="Visual Studio Properties" class="size-full wp-image-729 align-right" src="http://c0348292.cdn.cloudfiles.rackspacecloud.com/wp-content/uploads/2009/07/visual_studio_properties.png" style="width: 323px; height: 105px;" />
<p>C# lets the programming define a default value on a class property, so that GUI widgets can test the property to see if it still has the default value.  Visual Studio, for example, bolds any properties that have a non-default value, making them easy to pick out.</p>
<p>Unfortunately, the default value isn't used to actually initialize the property.  The initialization must be done elsewhere in the code, typically in the class's constructor.  Having to type the same value in two separate places in the code is error-prone, since it's easy to inadvertently change the value in one place and forget to change it in the other.</p>
<span id="more-720"></span>
<div class="highlight"><pre><span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">Widget</span>
{
<span style="color: #7D9029">    [DefaultValue(5)]</span>
    <span style="color: #008000; font-weight: bold">public</span> <span style="color: #B00040">int</span> WidgetLength { <span style="color: #008000; font-weight: bold">get</span>; <span style="color: #008000; font-weight: bold">set</span>; }

    <span style="color: #008000; font-weight: bold">public</span> <span style="color: #0000FF">Widget</span>()
    {
         WidgetLength = <span style="color: #666666">5</span>;
    }
}
</pre></div>
<p>With only one property in the class, the chances of an error are small.  However, when you have dozens of properties and the constructor is hundreds of lines away from the DefaultValue, mismatches are bound to happen.  Furthermore, <a class="reference external" href="http://stackoverflow.com/questions/40730/how-do-you-give-a-c-auto-property-a-default-value/40734#40734">so</a> <a class="reference external" href="http://www.eggheadcafe.com/software/aspnet/32319410/defaultvalue-attribute-on.aspx">many</a> <a class="reference external" href="http://jalpesh.blogspot.com/2007/03/how-to-set-default-value-of-property-in.html">people</a> assume that setting the DefaultValue will initialize the property that Microsoft issued a <a class="reference external" href="http://support.microsoft.com/kb/311339">Knowledge Base bulletin</a> to clarify the matter.  (Why can't they just make the documentation more explicit?)</p>
<p>Since I hate maintaining error-prone code, I wrote a function that initializes all of an instance's properties using the DefaultValue attributes.  I can set the DefaultValue attribute on each property, call the function once in the constructor, and forget about it.</p>
<div class="highlight"><pre><span style="color: #008000; font-weight: bold">static</span> <span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">void</span> <span style="color: #0000FF">ApplyDefaultValues</span>(<span style="color: #B00040">object</span> self)
{
     <span style="color: #008000; font-weight: bold">foreach</span> (PropertyDescriptor prop <span style="color: #008000; font-weight: bold">in</span> TypeDescriptor.GetProperties(self)) {
         DefaultValueAttribute attr = prop.Attributes[<span style="color: #008000; font-weight: bold">typeof</span>(DefaultValueAttribute)] <span style="color: #008000; font-weight: bold">as</span> DefaultValueAttribute;
         <span style="color: #008000; font-weight: bold">if</span> (attr == <span style="color: #008000; font-weight: bold">null</span>) <span style="color: #008000; font-weight: bold">continue</span>;
         prop.SetValue(self, attr.Value);
     }
}
</pre></div>

]]></content:encoded>
			<wfw:commentRss>http://www.barsoom.org/defaultvalue-attribute-initial/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!--

Minified using file
Page Caching using apc
Database Caching 123/137 queries in 0.024 seconds using apc
Content Delivery Network via c0348292.cdn.cloudfiles.rackspacecloud.com

Served from: almond.barsoom.org @ 2010-07-31 12:21:45 -->