<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>OOP - There It Is</title>
    <link>http://www.vpsw.com/blogbaby/</link>
    <description>A Very Practical Blog</description>
    <language>en-us</language>
    <copyright>Dean Fiala</copyright>
    <lastBuildDate>Wed, 18 Jan 2012 03:02:33 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>dfiala@vpsw.com</managingEditor>
    <webMaster>dfiala@vpsw.com</webMaster>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=5f888e1b-d9a5-4c20-b793-a46f09f3addd</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,5f888e1b-d9a5-4c20-b793-a46f09f3addd.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,5f888e1b-d9a5-4c20-b793-a46f09f3addd.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=5f888e1b-d9a5-4c20-b793-a46f09f3addd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Big thanks to Ganesan and the rest of <a href="http://www.dcdnug.org/dnn/default.aspx" target="_blank">DC
DNUG</a> for having me present tonight.  They asked great questions and even
provided a speaker gift!   
</p>
        <p>
And Metro delivered me on time and got me safely home on a surprisingly pleasant January
night.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5f888e1b-d9a5-4c20-b793-a46f09f3addd" />
      </body>
      <title>Breaking The If Habit–DC DNUG Style</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,5f888e1b-d9a5-4c20-b793-a46f09f3addd.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,5f888e1b-d9a5-4c20-b793-a46f09f3addd.aspx</link>
      <pubDate>Wed, 18 Jan 2012 03:02:33 GMT</pubDate>
      <description>&lt;p&gt;
Big thanks to Ganesan and the rest of &lt;a href="http://www.dcdnug.org/dnn/default.aspx" target="_blank"&gt;DC
DNUG&lt;/a&gt; for having me present tonight.&amp;#160; They asked great questions and even
provided a speaker gift!&amp;#160;&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
And Metro delivered me on time and got me safely home on a surprisingly pleasant January
night.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5f888e1b-d9a5-4c20-b793-a46f09f3addd" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,5f888e1b-d9a5-4c20-b793-a46f09f3addd.aspx</comments>
      <category>.NET</category>
      <category>Design Patterns</category>
      <category>Resharper</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=f352fe2c-e153-4499-9b68-a8eb33a233b2</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,f352fe2c-e153-4499-9b68-a8eb33a233b2.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,f352fe2c-e153-4499-9b68-a8eb33a233b2.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=f352fe2c-e153-4499-9b68-a8eb33a233b2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I followed through on my threat to do a presentation on using tiny objects. My supposition
is that most developers (myself included) resist creating trivial (tiny) objects even
when they could clean up code. Objects don’t have to possess lots of properties or
methods to become useful.
</p>
        <p>
Let’s take this example…
</p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">Random _randy = new Random(); 
<br />
public List&lt;double&gt; TestSeriesPoints(int numberOfPoints, double minValue, double
maxValue) 
<br />
{ 
<br />
    if(minValue &gt;= maxValue) 
<br />
    { 
<br />
       throw new Exception("minValue must be less
than maxValue"); 
<br />
    }</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    List&lt;double&gt;
points = new List&lt;double&gt;(); 
<br />
    for (int pointIndex = 0; pointIndex &lt; numberOfPoints; pointIndex++) 
<br />
    { 
<br />
        double point = _randy.NextDouble() * (maxValue
- minValue) + minValue; 
<br />
        points.Add(point); 
<br />
    } 
<br />
    return points; 
<br />
}</font>
        </p>
        <p>
It is a pretty straightforward method that returns some test data within the range
of a min and max value.  It’s a short method, and pretty easy to grok, so 99
times out 100, it wouldn’t be given a second glance.  But there is a tiny object
buried in here, one that will not only make this code cleaner, it will make modifying
it easier too. 
</p>
        <p>
Any time we see two variables that are always used in tandem, it is time to make a
Tiny Object…
</p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">Random _randy = new Random(); 
<br />
public List&lt;double&gt; TestSeriesPoints(int numberOfPoints, double <font style="background-color: #ffff00">minValue</font>,
double <font style="background-color: #ffff00">maxValue</font>) 
<br />
{ 
<br />
    if(<font style="background-color: #ffff00">minValue</font> &gt;= <font style="background-color: #ffff00">maxValue</font>) 
<br />
    { 
<br />
       throw new Exception("minValue must be less
than maxValue"); 
<br />
    }</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    List&lt;double&gt;
points = new List&lt;double&gt;(); 
<br />
    for (int pointIndex = 0; pointIndex &lt; numberOfPoints; pointIndex++) 
<br />
    { 
<br />
        double point = _randy.NextDouble() * (<font style="background-color: #ffff00">maxValue</font> - <font style="background-color: #ffff00">minValue</font>)
+ <font style="background-color: #ffff00">minValue</font>; 
<br />
        points.Add(point); 
<br />
    } 
<br />
    return points; 
<br />
}</font>
        </p>
        <p>
Where there’s a min value, there’s bound to be a max value. They don’t exist without
each other, so let’s make the commitment and formalize the relationship…
</p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">public class DoubleRange 
<br />
{ 
<br />
    public double MinValue = 0; 
<br />
    public double MaxValue = 100; 
<br />
}</font>
        </p>
        <p>
By combining two floating (but always proximate) variables into a single Tiny Object,
we’ve pulled ourselves out of procedural thinking and opened up the OOP world. 
We could leave it like this and still get some some benefits.  But by its mere
creation, our new Tiny Object has given us something concrete to work with and re-use.
It gives us a place to add behaviors and properties that consuming code will no longer
have to repeatedly re-implement.
</p>
        <p>
Once this object has materialized, it becomes apparent we can ensure that our range
is always valid by using a constructor and encapsulated properties.  And we can
turn the actual range of our DoubleRange into a property, so the consuming code does
not have to recalculate it. Finally, we can also create default constructor that sets
our range to have common min and max values.
</p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">public class DoubleRange 
<br />
{ 
<br />
    private double _minValue; 
<br />
    private double _maxValue;</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    public DataRange():this(0,100) 
<br />
    { 
<br />
    }</font>
          <font color="#0000ff" size="2" face="Courier New">
            <br />
    public DataRange(double minValue, double maxValue) 
<br />
    { 
<br />
        if(minValue &gt;= maxValue) 
<br />
        { 
<br />
             throw new
Exception("minValue must be less than maxValue"); 
<br />
        } 
<br />
        _minValue = minValue; 
<br />
        _maxValue = maxValue; 
<br />
    }</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    public double
MinValue 
<br />
    { 
<br />
        get{return _minValue;} 
<br />
    }</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    public double
MaxValue 
<br />
    { 
<br />
        get{return _maxValue;} 
<br />
    }</font>
        </p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">    public Range 
<br />
    { 
<br />
        get{return MaxValue - MinValue;} 
<br />
    } 
<br />
} 
<br /></font>
        </p>
        <p>
Our consuming code can boil off some logic that lives in the Tiny Object, so it looks
like this…
</p>
        <font color="#0000ff" size="2" face="Courier New">Random _randy = new Random(); 
<br />
public List&lt;double&gt; TestSeriesPoints(int numberOfPoints, DoubleRange testDataRange) 
<br />
{ 
<br />
    List&lt;double&gt; points = new List&lt;double&gt;(); 
<br />
    for (int pointIndex = 0; pointIndex &lt; numberOfPoints; pointIndex++) 
<br />
    { 
<br />
        double point = _randy.NextDouble() * testDataRange.Range
+ <font style="background-color: #ffffff">testDataRange.MinValue</font>; 
<br />
        points.Add(point); 
<br />
    } 
<br />
    return points; 
<br />
}</font>
        <p>
Our Tiny Object has grown into something useful… 
</p>
        <ul>
          <li>
the consuming code is clearer, working with a DoubleRange object, not some implicitly
related values</li>
          <li>
the unexplained (maxValue – minValue) expression in our calculation is explicitly
defined in its new object home</li>
          <li>
the object handles its own validation</li>
        </ul>
        <p>
Finally, adding one small method to our Tiny Object will also make debugging 
and logging easier…
</p>
        <p>
          <font color="#0000ff" size="2" face="Courier New">public override ToString() 
<br /></font>
          <font color="#0000ff" size="2" face="Courier New">{ 
<br />
   return string.Format("Range {0:n4} to {1:n4}", _minValue, _maxValue); 
<br />
}</font>
        </p>
        <p>
Now, any time the object is added to a log statement, we’ll always see the current
range values like so…
</p>
        <p>
          <font color="#9b00d3" size="2" face="Courier New">Range 0.0000 to 100.0000</font>
        </p>
        <p>
That gives us three of the four joys of OOP -- abstraction, encapsulation,  and
polymorphism – all in one Tiny Object.  
</p>
        <p>
So the next time you see two or three variable spending a lot of time together, do
the right thing move them into their own Tiny Object and see what other  wonderful
attributes and behaviors blossom.
</p>
        <p>
And always remember there are no Tiny Objects, only tiny developers.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=f352fe2c-e153-4499-9b68-a8eb33a233b2" />
      </body>
      <title>Tiny Objects</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,f352fe2c-e153-4499-9b68-a8eb33a233b2.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,f352fe2c-e153-4499-9b68-a8eb33a233b2.aspx</link>
      <pubDate>Sun, 18 Dec 2011 21:09:56 GMT</pubDate>
      <description>&lt;p&gt;
I followed through on my threat to do a presentation on using tiny objects. My supposition
is that most developers (myself included) resist creating trivial (tiny) objects even
when they could clean up code. Objects don’t have to possess lots of properties or
methods to become useful.
&lt;/p&gt;
&lt;p&gt;
Let’s take this example…
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;Random _randy = new Random(); 
&lt;br /&gt;
public List&amp;lt;double&amp;gt; TestSeriesPoints(int numberOfPoints, double minValue, double
maxValue) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; if(minValue &amp;gt;= maxValue) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new Exception(&amp;quot;minValue must be less
than maxValue&amp;quot;); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; List&amp;lt;double&amp;gt;
points = new List&amp;lt;double&amp;gt;(); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; for (int pointIndex = 0; pointIndex &amp;lt; numberOfPoints; pointIndex++) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; double point = _randy.NextDouble() * (maxValue
- minValue) + minValue; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; points.Add(point); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; return points; 
&lt;br /&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
It is a pretty straightforward method that returns some test data within the range
of a min and max value.&amp;#160; It’s a short method, and pretty easy to grok, so 99
times out 100, it wouldn’t be given a second glance.&amp;#160; But there is a tiny object
buried in here, one that will not only make this code cleaner, it will make modifying
it easier too. 
&lt;/p&gt;
&lt;p&gt;
Any time we see two variables that are always used in tandem, it is time to make a
Tiny Object…
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;Random _randy = new Random(); 
&lt;br /&gt;
public List&amp;lt;double&amp;gt; TestSeriesPoints(int numberOfPoints, double &lt;font style="background-color: #ffff00"&gt;minValue&lt;/font&gt;,
double &lt;font style="background-color: #ffff00"&gt;maxValue&lt;/font&gt;) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; if(&lt;font style="background-color: #ffff00"&gt;minValue&lt;/font&gt; &amp;gt;= &lt;font style="background-color: #ffff00"&gt;maxValue&lt;/font&gt;) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new Exception(&amp;quot;minValue must be less
than maxValue&amp;quot;); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; List&amp;lt;double&amp;gt;
points = new List&amp;lt;double&amp;gt;(); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; for (int pointIndex = 0; pointIndex &amp;lt; numberOfPoints; pointIndex++) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; double point = _randy.NextDouble() * (&lt;font style="background-color: #ffff00"&gt;maxValue&lt;/font&gt; - &lt;font style="background-color: #ffff00"&gt;minValue&lt;/font&gt;)
+ &lt;font style="background-color: #ffff00"&gt;minValue&lt;/font&gt;; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; points.Add(point); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; return points; 
&lt;br /&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Where there’s a min value, there’s bound to be a max value. They don’t exist without
each other, so let’s make the commitment and formalize the relationship…
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;public class DoubleRange 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; public double MinValue = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; public double MaxValue = 100; 
&lt;br /&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
By combining two floating (but always proximate) variables into a single Tiny Object,
we’ve pulled ourselves out of procedural thinking and opened up the OOP world.&amp;#160;
We could leave it like this and still get some some benefits.&amp;#160; But by its mere
creation, our new Tiny Object has given us something concrete to work with and re-use.
It gives us a place to add behaviors and properties that consuming code will no longer
have to repeatedly re-implement.
&lt;/p&gt;
&lt;p&gt;
Once this object has materialized, it becomes apparent we can ensure that our range
is always valid by using a constructor and encapsulated properties.&amp;#160; And we can
turn the actual range of our DoubleRange into a property, so the consuming code does
not have to recalculate it. Finally, we can also create default constructor that sets
our range to have common min and max values.
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;public class DoubleRange 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; private double _minValue; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; private double _maxValue;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; public DataRange():this(0,100) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;&lt;font color="#0000ff" size="2" face="Courier New"&gt; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; public DataRange(double minValue, double maxValue) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(minValue &amp;gt;= maxValue) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; throw new
Exception(&amp;quot;minValue must be less than maxValue&amp;quot;); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _minValue = minValue; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _maxValue = maxValue; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; public double
MinValue 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get{return _minValue;} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; public double
MaxValue 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get{return _maxValue;} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; public Range 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get{return MaxValue - MinValue;} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
} 
&lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Our consuming code can boil off some logic that lives in the Tiny Object, so it looks
like this…
&lt;/p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;Random _randy = new Random(); 
&lt;br /&gt;
public List&amp;lt;double&amp;gt; TestSeriesPoints(int numberOfPoints, DoubleRange testDataRange) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; List&amp;lt;double&amp;gt; points = new List&amp;lt;double&amp;gt;(); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; for (int pointIndex = 0; pointIndex &amp;lt; numberOfPoints; pointIndex++) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; double point = _randy.NextDouble() * testDataRange.Range
+ &lt;font style="background-color: #ffffff"&gt;testDataRange.MinValue&lt;/font&gt;; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; points.Add(point); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; return points; 
&lt;br /&gt;
}&lt;/font&gt; 
&lt;p&gt;
Our Tiny Object has grown into something useful… 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
the consuming code is clearer, working with a DoubleRange object, not some implicitly
related values&lt;/li&gt;
&lt;li&gt;
the unexplained (maxValue – minValue) expression in our calculation is explicitly
defined in its new object home&lt;/li&gt;
&lt;li&gt;
the object handles its own validation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Finally, adding one small method to our Tiny Object will also make debugging&amp;#160;
and logging easier…
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="2" face="Courier New"&gt;public override ToString() 
&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2" face="Courier New"&gt;{ 
&lt;br /&gt;
&amp;#160;&amp;#160; return string.Format(&amp;quot;Range {0:n4} to {1:n4}&amp;quot;, _minValue, _maxValue); 
&lt;br /&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Now, any time the object is added to a log statement, we’ll always see the current
range values like so…
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#9b00d3" size="2" face="Courier New"&gt;Range 0.0000 to 100.0000&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
That gives us three of the four joys of OOP -- abstraction, encapsulation,&amp;#160; and
polymorphism – all in one Tiny Object.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So the next time you see two or three variable spending a lot of time together, do
the right thing move them into their own Tiny Object and see what other&amp;#160; wonderful
attributes and behaviors blossom.
&lt;/p&gt;
&lt;p&gt;
And always remember there are no Tiny Objects, only tiny developers.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=f352fe2c-e153-4499-9b68-a8eb33a233b2" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,f352fe2c-e153-4499-9b68-a8eb33a233b2.aspx</comments>
      <category>OOP</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=cf582d95-f460-44bb-8670-3558d2eee6e3</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,cf582d95-f460-44bb-8670-3558d2eee6e3.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,cf582d95-f460-44bb-8670-3558d2eee6e3.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=cf582d95-f460-44bb-8670-3558d2eee6e3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The links have the zipped versions of the <a href="http://www.vpsw.com/down/BreaktheIfHabit_Before.zip" target="_blank">before</a> and <a href="http://www.vpsw.com/down/BreaktheIfHabit_After.zip" target="_blank">after</a> refactoring
projects from the Break the If Habit presentation.  
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=cf582d95-f460-44bb-8670-3558d2eee6e3" />
      </body>
      <title>Break The If Habit – The Source Code</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,cf582d95-f460-44bb-8670-3558d2eee6e3.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,cf582d95-f460-44bb-8670-3558d2eee6e3.aspx</link>
      <pubDate>Wed, 16 Nov 2011 05:29:11 GMT</pubDate>
      <description>&lt;p&gt;
The links have the zipped versions of the &lt;a href="http://www.vpsw.com/down/BreaktheIfHabit_Before.zip" target="_blank"&gt;before&lt;/a&gt; and &lt;a href="http://www.vpsw.com/down/BreaktheIfHabit_After.zip" target="_blank"&gt;after&lt;/a&gt; refactoring
projects from the Break the If Habit presentation.&amp;#160; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=cf582d95-f460-44bb-8670-3558d2eee6e3" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,cf582d95-f460-44bb-8670-3558d2eee6e3.aspx</comments>
      <category>Design Patterns</category>
      <category>OOP</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=1f6dfe0b-fff3-4882-ab95-7ce984ca5b54</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,1f6dfe0b-fff3-4882-ab95-7ce984ca5b54.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,1f6dfe0b-fff3-4882-ab95-7ce984ca5b54.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=1f6dfe0b-fff3-4882-ab95-7ce984ca5b54</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I headed out to Columbia, Maryland this past weekend to speak at the <a href="http://www.cmap-online.org/CodeCamp/Sessions.aspx" target="_blank">CMAP
Fall 2011 Code Camp</a>. I was shocked that so many people wanted to see code refactoring
at 8:45 on a Saturday morning, but was happy to have an excellent crowd.
</p>
        <p>
The presentation was on breaking the If habit.  To steal the abstract…
</p>
        <blockquote>
          <p>
            <font color="#666666">Branching logic is one of the foundations of computer programming.
But like vodka, the If statement is best consumed in moderation. While the first If
is harmless, and maybe even a little thrilling, soon there's a second, a third, a
fourth and before you know it -- you wake up under your desk with a method you don't
even recognize much less understand.</font>
          </p>
          <p>
            <font color="#666666">In this session we'll explore some of the common If abuses and
learn how to refactor them into more readable and adaptable code. We'll use design
patterns to put the demon If back in its bottle and keep it there. Saner code is within
reach, and this is the first step to break the the If habit.</font>
          </p>
        </blockquote>
        <p>
The inspiration for this talk was some legacy code I had to update.  It was already
sagging under a dense thicket of if statements that crossed two methods and already
had 18 paths. I was supposed to add yet another set of if statements to support yet
another variation of the report this code generated.  
</p>
        <p>
I just couldn’t bring myself to do it.  It had taken me two hours to analyze
where the changes had to be made so they wouldn’t break anything else. I knew adding
these statements was just stuffing more complexity into two methods that were already
bursting with branching logic.  The next change would require even more analysis
and would more likely lead to something getting broken.
</p>
        <p>
So, I started ripping out code.  I’d like to claim I was purposefully refactoring
to a pattern, but it was really more instinctual, moving the code for each variation
into its own class.  What it turned out I was doing was <a href="http://refactoring.com/catalog/replaceConditionalWithPolymorphism.html" target="_blank">replacing
a conditional with polymorphism</a>, or implementing a <a href="http://www.oodesign.com/strategy-pattern.html" target="_blank">strategy
pattern</a>.
</p>
        <p>
The example from the talk started out looking like this…
</p>
        <blockquote>
          <p>
            <font color="#0000ff" size="1" face="Courier New">public double CalculateProfitSharing(Employee
employee, DateTime asOfDate, double grossProfit, EmployeeStats stats) 
<br />
       { 
<br />
           TimeSpan lengthofEmployment
= asOfDate - employee.StartDate; 
<br />
           double pool = grossProfit*0.04; 
<br />
           double profitSharingAmount
= 0; 
<br />
           if(lengthofEmployment.Days
&gt; 182) 
<br />
           { 
<br />
              
double basePartofPool = 1.0/(double)stats.EmployeeCount * pool; 
<br />
              
double loyaltyMultipler = lengthofEmployment.Days/stats.AverageLengthEmploymentinDays; 
<br />
              
<br />
              
//current year pro-rate 
<br />
              
double proratedRate = 1; 
<br />
              
if(lengthofEmployment.Days &lt; 365) 
<br />
              
{ 
<br />
                  
proratedRate = lengthofEmployment.Days/365.0; 
<br />
              
} 
<br />
              
profitSharingAmount = basePartofPool*loyaltyMultipler*proratedRate;</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">              
if(employee.Sales) 
<br />
              
{ 
<br />
                  
profitSharingAmount = 0; 
<br />
              
} 
<br />
              
else if(employee.Level &lt; 4) 
<br />
              
{ 
<br />
                  
if(employee.Level == 2) 
<br />
                  
{ 
<br />
                      
profitSharingAmount *= 1.5; 
<br />
                  
} 
<br />
                  
else if(employee.Level == 3) 
<br />
                  
{ 
<br />
                      
profitSharingAmount *= 2; 
<br />
                  
} 
<br />
                  
if (profitSharingAmount  &gt; 10000) 
<br />
                  
{ 
<br />
                      
profitSharingAmount = 10000; 
<br />
                  
} 
<br />
              
} 
<br />
              
else 
<br />
              
{ 
<br />
                  
profitSharingAmount *= 2.5; 
<br />
                  
if(profitSharingAmount &gt; 5000) 
<br />
                  
{ 
<br />
                      
profitSharingAmount = 5000; 
<br />
                  
} 
<br />
              
} 
<br />
           } 
<br />
           if(profitSharingAmount
&lt;0 &amp; employee.Level &lt; 4) 
<br />
           { 
<br />
              
profitSharingAmount = 0; 
<br />
           } 
<br />
           if(employee.Level ==
4) 
<br />
           { 
<br />
              
if(profitSharingAmount &lt; -5000) 
<br />
              
{ 
<br />
                  
profitSharingAmount = -5000; 
<br />
              
}</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">              
if(profitSharingAmount &gt; 0) 
<br />
              
{ 
<br />
                   
<br />
                  
if((asOfDate - employee.LastOptionGrant).Days&lt;= 365) 
<br />
                  
{ 
<br />
                      
profitSharingAmount = 0; 
<br />
                  
} 
<br />
              
} 
<br />
           } 
<br />
           if(employee.Level &lt;
4) 
<br />
           { 
<br />
              
if(employee.ChoseDeferred) 
<br />
              
{ 
<br />
                  
profitSharingAmount *= 1.25; 
<br />
              
} 
<br />
           } 
<br />
           return Math.Ceiling(profitSharingAmount); 
<br />
       } 
<br /></font>
          </p>
        </blockquote>
        <p>
And ended up looking like this... 
</p>
        <blockquote>
          <p>
            <font color="#0000ff" size="1" face="Courier New">public double CalculateProfitSharing(Employee
employee, DateTime asOfDate, double grossProfit, EmployeeStats stats) 
<br />
{ 
<br />
     var profitSharingLevel = GetProfitSharingLevel(employee); 
<br />
     return profitSharingLevel.CalculateProfitSharing(employee,
asOfDate, grossProfit, stats); 
<br />
}</font>
          </p>
        </blockquote>
        <blockquote>
          <p>
            <font color="#0000ff" size="1" face="Courier New">private ProfitSharingEmployeeLevelBase
GetProfitSharingLevel(Employee employee) 
<br />
{ 
<br />
     if(profitSharingLevels.ContainsKey(employee.Level)) 
<br />
     { 
<br />
         return profitSharingLevels[employee.Level]; 
<br />
     }</font>
          </p>
          <p>
            <font size="1" face="Courier New">
              <font color="#0000ff">     return
new ProfitSharingEmployeeLevelNullObject(); 
<br /></font>} 
<br /></font>
          </p>
        </blockquote>
        <p>
There is obviously some code in the new classes that encapsulates the variations so
there is not a reduction in the total amount of code. But every method becomes much
each easier to understand when you don’t have scroll to through pages of nested if
statements.  It also becomes easier to change and maintain code when your rules
for each variation aren’t tangled together in gobs of if statements.
</p>
        <p>
The presentation also included how to use the <a href="http://cs.oberlin.edu/~jwalker/nullObjPattern/" target="_blank">Null
Object Pattern</a> so you can stop sprinkling your code with null checks (there’s
an example above – just imagine GetProfitSharingLevel is public and is called by more
than one other method). It was also supposed to show the replacement of branching
logic with the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank">Decorator
Pattern</a>, but we ran out of time. I’ll try to explore these in more detail in other
blog posts, but not tonight.
</p>
        <p>
I think the root cause of most If abuse is the refusal of developers to create objects,
especially small ones.  I think there is an innate aversion to creating seemingly
trivial objects no matter how helpful they might be.  Packaging two pieces of
related information and/or a method together should be reason enough to make a new
class, but that doesn’t seem to pass the “I need a new class” threshold for most developers.
I know it’s below mine.  
</p>
        <p>
For instance, implementing a calculation for a tiered sales commission is usually
done with if statements.  
</p>
        <blockquote>
          <p>
            <font size="1" face="Courier New">    <font color="#0000ff">double
commission = 0; 
<br />
                
if (yearSales &lt; yearTarget) 
<br />
                
{ 
<br />
                    
commission = 0.005 * yearSales; 
<br />
                
} 
<br />
                
else if (yearSales &lt; yearTarget*2) 
<br />
                
{ 
<br />
                    
commission = 0.01 * (yearSales - yearTarget) + 0.005 * yearTarget; 
<br />
                
} 
<br />
                
else 
<br />
                
{ 
<br />
                    
commission = 0.02*(yearSales - yearTarget*2) + 0.01 * yearTarget + 0.005 * yearTarget; 
<br />
                
} 
<br />
                
compensation += commission;</font></font></p>
        </blockquote>
        <p>
And it’s fine, it works, it is even fairly compact  – but it takes a while to
understand, extending it requires additional if statements and it is buried inside
a method – wholly unusable anywhere else.  But the worst sin is that we have
a clear object here with two properties and a method, and we have denied its existence.
</p>
        <p>
What we should do is create a small object…
</p>
        <blockquote>
          <p>
            <font color="#0000ff" size="1" face="Courier New">public class CommissionTier 
<br />
    { 
<br />
        private double _tierStart; 
<br />
        private double _rate;</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">       
public CommissionTier(double tierStart, double rate) 
<br />
        { 
<br />
            _tierStart = tierStart; 
<br />
            _rate = rate; 
<br />
        }</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">       
public double TierStart 
<br />
        { 
<br />
            get { return _tierStart;
} 
<br />
        }</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">       
public double GetCommision(double sales) 
<br />
        { 
<br />
            return (sales -
TierStart)*_rate; 
<br />
        }</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">       
public override string ToString() 
<br />
        { 
<br />
            return string.Format("Tier
Start:{0:c0}, Rate {1:0.00%}", _tierStart, _rate); 
<br />
        } 
<br />
    } 
<br /></font>
          </p>
        </blockquote>
        <p>
Then we can use a looping structure that is more clear about what we’re doing. It
is also now easily extensible.  To add a tier, we just need to add a new instance
of the CommissionTier object to the collection – no logic changes required. 
Heck we could even drive tier creation from a database…
</p>
        <blockquote>
          <p>
            <font color="#0000ff" size="1" face="Courier New">_tiers.Add(new CommissionTier(yearTarget
* 2, 0.02)); 
<br />
_tiers.Add(new CommissionTier(yearTarget, 0.01)); 
<br />
_tiers.Add(new CommissionTier(0, 0.005));</font>
          </p>
          <p>
            <font color="#0000ff" size="1" face="Courier New">double commission = 0; 
<br />
double workingSales = yearSales; 
<br />
foreach (CommissionTier tier in _tiers) 
<br />
{ 
<br />
    if (workingSales &gt; tier.TierStart) 
<br />
    { 
<br />
        commission += tier.GetCommision(workingSales); 
<br />
        workingSales = tier.TierStart; 
<br />
    } 
<br />
}   </font>
          </p>
        </blockquote>
        <p>
By promoting the Commission Tier to an object instead of leaving it strewn about in
manually related variables, magic numbers and calculations, all of sudden we have
all the tools of OOP available to us. Our logic and our data are packaged together
nicely.  The object has control of its data and we can leverage the power of
collections.  
</p>
        <p>
So instead continuing to pack procedural programming spaghetti into our methods, we
need to be object oriented designers and create more frickin’ objects. Only then can
we begin to break the If habit.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=1f6dfe0b-fff3-4882-ab95-7ce984ca5b54" />
      </body>
      <title>Break The If Habit</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,1f6dfe0b-fff3-4882-ab95-7ce984ca5b54.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,1f6dfe0b-fff3-4882-ab95-7ce984ca5b54.aspx</link>
      <pubDate>Wed, 16 Nov 2011 05:03:34 GMT</pubDate>
      <description>&lt;p&gt;
I headed out to Columbia, Maryland this past weekend to speak at the &lt;a href="http://www.cmap-online.org/CodeCamp/Sessions.aspx" target="_blank"&gt;CMAP
Fall 2011 Code Camp&lt;/a&gt;. I was shocked that so many people wanted to see code refactoring
at 8:45 on a Saturday morning, but was happy to have an excellent crowd.
&lt;/p&gt;
&lt;p&gt;
The presentation was on breaking the If habit.&amp;#160; To steal the abstract…
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#666666"&gt;Branching logic is one of the foundations of computer programming.
But like vodka, the If statement is best consumed in moderation. While the first If
is harmless, and maybe even a little thrilling, soon there's a second, a third, a
fourth and before you know it -- you wake up under your desk with a method you don't
even recognize much less understand.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#666666"&gt;In this session we'll explore some of the common If abuses and
learn how to refactor them into more readable and adaptable code. We'll use design
patterns to put the demon If back in its bottle and keep it there. Saner code is within
reach, and this is the first step to break the the If habit.&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The inspiration for this talk was some legacy code I had to update.&amp;#160; It was already
sagging under a dense thicket of if statements that crossed two methods and already
had 18 paths. I was supposed to add yet another set of if statements to support yet
another variation of the report this code generated.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
I just couldn’t bring myself to do it.&amp;#160; It had taken me two hours to analyze
where the changes had to be made so they wouldn’t break anything else. I knew adding
these statements was just stuffing more complexity into two methods that were already
bursting with branching logic.&amp;#160; The next change would require even more analysis
and would more likely lead to something getting broken.
&lt;/p&gt;
&lt;p&gt;
So, I started ripping out code.&amp;#160; I’d like to claim I was purposefully refactoring
to a pattern, but it was really more instinctual, moving the code for each variation
into its own class.&amp;#160; What it turned out I was doing was &lt;a href="http://refactoring.com/catalog/replaceConditionalWithPolymorphism.html" target="_blank"&gt;replacing
a conditional with polymorphism&lt;/a&gt;, or implementing a &lt;a href="http://www.oodesign.com/strategy-pattern.html" target="_blank"&gt;strategy
pattern&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The example from the talk started out looking like this…
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;public double CalculateProfitSharing(Employee
employee, DateTime asOfDate, double grossProfit, EmployeeStats stats) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; TimeSpan lengthofEmployment
= asOfDate - employee.StartDate; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; double pool = grossProfit*0.04; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; double profitSharingAmount
= 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(lengthofEmployment.Days
&amp;gt; 182) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
double basePartofPool = 1.0/(double)stats.EmployeeCount * pool; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
double loyaltyMultipler = lengthofEmployment.Days/stats.AverageLengthEmploymentinDays; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
//current year pro-rate 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
double proratedRate = 1; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(lengthofEmployment.Days &amp;lt; 365) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
proratedRate = lengthofEmployment.Days/365.0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = basePartofPool*loyaltyMultipler*proratedRate;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(employee.Sales) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
else if(employee.Level &amp;lt; 4) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(employee.Level == 2) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount *= 1.5; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
else if(employee.Level == 3) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount *= 2; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if (profitSharingAmount&amp;#160; &amp;gt; 10000) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = 10000; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
else 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount *= 2.5; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(profitSharingAmount &amp;gt; 5000) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = 5000; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(profitSharingAmount
&amp;lt;0 &amp;amp; employee.Level &amp;lt; 4) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(employee.Level ==
4) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(profitSharingAmount &amp;lt; -5000) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = -5000; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(profitSharingAmount &amp;gt; 0) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if((asOfDate - employee.LastOptionGrant).Days&amp;lt;= 365) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(employee.Level &amp;lt;
4) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if(employee.ChoseDeferred) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
profitSharingAmount *= 1.25; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return Math.Ceiling(profitSharingAmount); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
And ended up looking like this... 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;public double CalculateProfitSharing(Employee
employee, DateTime asOfDate, double grossProfit, EmployeeStats stats) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; var profitSharingLevel = GetProfitSharingLevel(employee); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; return profitSharingLevel.CalculateProfitSharing(employee,
asOfDate, grossProfit, stats); 
&lt;br /&gt;
}&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;private ProfitSharingEmployeeLevelBase
GetProfitSharingLevel(Employee employee) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; if(profitSharingLevels.ContainsKey(employee.Level)) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return profitSharingLevels[employee.Level]; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1" face="Courier New"&gt;&lt;font color="#0000ff"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return
new ProfitSharingEmployeeLevelNullObject(); 
&lt;br /&gt;
&lt;/font&gt;} 
&lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
There is obviously some code in the new classes that encapsulates the variations so
there is not a reduction in the total amount of code. But every method becomes much
each easier to understand when you don’t have scroll to through pages of nested if
statements.&amp;#160; It also becomes easier to change and maintain code when your rules
for each variation aren’t tangled together in gobs of if statements.
&lt;/p&gt;
&lt;p&gt;
The presentation also included how to use the &lt;a href="http://cs.oberlin.edu/~jwalker/nullObjPattern/" target="_blank"&gt;Null
Object Pattern&lt;/a&gt; so you can stop sprinkling your code with null checks (there’s
an example above – just imagine GetProfitSharingLevel is public and is called by more
than one other method). It was also supposed to show the replacement of branching
logic with the &lt;a href="http://en.wikipedia.org/wiki/Decorator_pattern" target="_blank"&gt;Decorator
Pattern&lt;/a&gt;, but we ran out of time. I’ll try to explore these in more detail in other
blog posts, but not tonight.
&lt;/p&gt;
&lt;p&gt;
I think the root cause of most If abuse is the refusal of developers to create objects,
especially small ones.&amp;#160; I think there is an innate aversion to creating seemingly
trivial objects no matter how helpful they might be.&amp;#160; Packaging two pieces of
related information and/or a method together should be reason enough to make a new
class, but that doesn’t seem to pass the “I need a new class” threshold for most developers.
I know it’s below mine.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
For instance, implementing a calculation for a tiered sales commission is usually
done with if statements.&amp;#160; 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;font size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;font color="#0000ff"&gt;double
commission = 0; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
if (yearSales &amp;lt; yearTarget) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
commission = 0.005 * yearSales; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
else if (yearSales &amp;lt; yearTarget*2) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
commission = 0.01 * (yearSales - yearTarget) + 0.005 * yearTarget; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
else 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
commission = 0.02*(yearSales - yearTarget*2) + 0.01 * yearTarget + 0.005 * yearTarget; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
compensation += commission;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
And it’s fine, it works, it is even fairly compact&amp;#160; – but it takes a while to
understand, extending it requires additional if statements and it is buried inside
a method – wholly unusable anywhere else.&amp;#160; But the worst sin is that we have
a clear object here with two properties and a method, and we have denied its existence.
&lt;/p&gt;
&lt;p&gt;
What we should do is create a small object…
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;public class CommissionTier 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private double _tierStart; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; private double _rate;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
public CommissionTier(double tierStart, double rate) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _tierStart = tierStart; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _rate = rate; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
public double TierStart 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _tierStart;
} 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
public double GetCommision(double sales) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return (sales -
TierStart)*_rate; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
public override string ToString() 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; return string.Format(&amp;quot;Tier
Start:{0:c0}, Rate {1:0.00%}&amp;quot;, _tierStart, _rate); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Then we can use a looping structure that is more clear about what we’re doing. It
is also now easily extensible.&amp;#160; To add a tier, we just need to add a new instance
of the CommissionTier object to the collection – no logic changes required.&amp;#160;
Heck we could even drive tier creation from a database…
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;_tiers.Add(new CommissionTier(yearTarget
* 2, 0.02)); 
&lt;br /&gt;
_tiers.Add(new CommissionTier(yearTarget, 0.01)); 
&lt;br /&gt;
_tiers.Add(new CommissionTier(0, 0.005));&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0000ff" size="1" face="Courier New"&gt;double commission = 0; 
&lt;br /&gt;
double workingSales = yearSales; 
&lt;br /&gt;
foreach (CommissionTier tier in _tiers) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; if (workingSales &amp;gt; tier.TierStart) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; commission += tier.GetCommision(workingSales); 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; workingSales = tier.TierStart; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; } 
&lt;br /&gt;
}&amp;#160;&amp;#160; &lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
By promoting the Commission Tier to an object instead of leaving it strewn about in
manually related variables, magic numbers and calculations, all of sudden we have
all the tools of OOP available to us. Our logic and our data are packaged together
nicely.&amp;#160; The object has control of its data and we can leverage the power of
collections.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So instead continuing to pack procedural programming spaghetti into our methods, we
need to be object oriented designers and create more frickin’ objects. Only then can
we begin to break the If habit.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=1f6dfe0b-fff3-4882-ab95-7ce984ca5b54" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,1f6dfe0b-fff3-4882-ab95-7ce984ca5b54.aspx</comments>
      <category>Design Patterns</category>
      <category>OOP</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have been doing more with LINQ and extension methods of late and thought I should
delve a (little) more deeply into the somewhat mysterious <strong>=&gt;</strong> operator. 
So I did a little reading, a little <a href="../down/LambdaLambdaLambda.zip" target="_blank">coding</a> and
little <a href="../down/LambdaLambdaLambda.ppt" target="_blank">PowerPoint</a> presentation
and did a n00b presentation at <a href="http://www.Rocknug.org" target="_blank">RockNUG</a> this
month.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2" />
      </body>
      <title>Lambda, Lambda, Lambda</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2.aspx</link>
      <pubDate>Thu, 16 Jun 2011 01:23:49 GMT</pubDate>
      <description>&lt;p&gt;
I have been doing more with LINQ and extension methods of late and thought I should
delve a (little) more deeply into the somewhat mysterious &lt;strong&gt;=&amp;gt;&lt;/strong&gt; operator.&amp;nbsp;
So I did a little reading, a little &lt;a href="../down/LambdaLambdaLambda.zip" target="_blank"&gt;coding&lt;/a&gt; and
little &lt;a href="../down/LambdaLambdaLambda.ppt" target="_blank"&gt;PowerPoint&lt;/a&gt; presentation
and did a n00b presentation at &lt;a href="http://www.Rocknug.org" target="_blank"&gt;RockNUG&lt;/a&gt; this
month.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,b1408fdc-39ea-43a9-b4c8-b6fbb0bc71f2.aspx</comments>
      <category>.NET</category>
      <category>Lambda</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=f9f15955-6f07-4eae-9f16-c3c6b5be1429</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,f9f15955-6f07-4eae-9f16-c3c6b5be1429.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,f9f15955-6f07-4eae-9f16-c3c6b5be1429.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=f9f15955-6f07-4eae-9f16-c3c6b5be1429</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My, it has been a while.  I'd like to claim that I was off doing something of
world shaking import, or at least developing software that no one can live without,
but frankly it was just the daily grind(s) that kept me from adding a few more kilobytes
to the internet's ever expanding waistline.
</p>
        <p>
I'm back because I’ve been doing short Design Pattern presentations for <a href="http://www.rocknug.org">Rock
NUG</a>, and I have been promising to post the power points and code for months, so
why not now? Why not here?
</p>
        <p>
I’ve just been following the fun and informative, <a href="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124">Head
First Design Patterns</a>, which is a Java book (shhhh!), and working up some C# examples. 
</p>
        <h3>Observer Pattern
</h3>
        <p>
Hold on loosely, but keep in the know.
</p>
        <p>
          <a href="http://www.vpsw.com/down/ObserverPattern.zip">Source</a>
        </p>
        <p>
          <a href="http://www.vpsw.com/down/ObserverPattern.ppt">Presentation</a>
        </p>
        <h3>Decorator Pattern
</h3>
        <p>
Make objects open for extension, but closed for modification.
</p>
        <p>
          <a href="http://www.vpsw.com/down/DecoratorPattern.zip">Source</a>
        </p>
        <p>
          <a href="http://www.vpsw.com/down/DecoratorPattern.ppt">Presentation</a>
        </p>
        <h3>Factory Pattern
</h3>
        <p>
Code around abstractions, not implementations. 
</p>
        <p>
          <a href="http://www.vpsw.com/down/FactoryPattern.zip">Source</a>
        </p>
        <p>
          <a href="http://www.vpsw.com/down/FactoryPattern.ppt">Presentation</a>
        </p>
        <h3>Singleton Pattern
</h3>
        <p>
One class to rule them all.
</p>
        <p>
          <a href="http://www.vpsw.com/down/SingletonPattern.zip">Source</a>
        </p>
        <p>
          <a href="http://www.vpsw.com/down/SingletonPattern.ppt">Presentation</a>
        </p>
        <p>
That’s it for now.  Stay tuned next (indeterminate period of time) for more Design
Pattern fun.
</p>
        <p>
PS.  Was feeling a little retro, so all the files were uploaded using command
line FTP.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=f9f15955-6f07-4eae-9f16-c3c6b5be1429" />
      </body>
      <title>Dusting Off The Cobwebs</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,f9f15955-6f07-4eae-9f16-c3c6b5be1429.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,f9f15955-6f07-4eae-9f16-c3c6b5be1429.aspx</link>
      <pubDate>Fri, 14 Jan 2011 07:25:00 GMT</pubDate>
      <description>&lt;p&gt;
My, it has been a while.&amp;#160; I'd like to claim that I was off doing something of
world shaking import, or at least developing software that no one can live without,
but frankly it was just the daily grind(s) that kept me from adding a few more kilobytes
to the internet's ever expanding waistline.
&lt;/p&gt;
&lt;p&gt;
I'm back because I’ve been doing short Design Pattern presentations for &lt;a href="http://www.rocknug.org"&gt;Rock
NUG&lt;/a&gt;, and I have been promising to post the power points and code for months, so
why not now? Why not here?
&lt;/p&gt;
&lt;p&gt;
I’ve just been following the fun and informative, &lt;a href="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124"&gt;Head
First Design Patterns&lt;/a&gt;, which is a Java book (shhhh!), and working up some C# examples. 
&lt;/p&gt;
&lt;h3&gt;Observer Pattern
&lt;/h3&gt;
&lt;p&gt;
Hold on loosely, but keep in the know.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/ObserverPattern.zip"&gt;Source&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/ObserverPattern.ppt"&gt;Presentation&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Decorator Pattern
&lt;/h3&gt;
&lt;p&gt;
Make objects open for extension, but closed for modification.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/DecoratorPattern.zip"&gt;Source&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/DecoratorPattern.ppt"&gt;Presentation&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Factory Pattern
&lt;/h3&gt;
&lt;p&gt;
Code around abstractions, not implementations. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/FactoryPattern.zip"&gt;Source&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/FactoryPattern.ppt"&gt;Presentation&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Singleton Pattern
&lt;/h3&gt;
&lt;p&gt;
One class to rule them all.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/SingletonPattern.zip"&gt;Source&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.vpsw.com/down/SingletonPattern.ppt"&gt;Presentation&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
That’s it for now.&amp;#160; Stay tuned next (indeterminate period of time) for more Design
Pattern fun.
&lt;/p&gt;
&lt;p&gt;
PS.&amp;#160; Was feeling a little retro, so all the files were uploaded using command
line FTP.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=f9f15955-6f07-4eae-9f16-c3c6b5be1429" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,f9f15955-6f07-4eae-9f16-c3c6b5be1429.aspx</comments>
      <category>Design Patterns</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=5ebf2926-8003-4c16-b328-8e91755317b0</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,5ebf2926-8003-4c16-b328-8e91755317b0.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,5ebf2926-8003-4c16-b328-8e91755317b0.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=5ebf2926-8003-4c16-b328-8e91755317b0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Resharper cult members already know this, but for those who haven't joined yet,
version <a href="http://www.jetbrains.com/resharper/download/">4.0 released today</a> with
VS 2008 support -- huzzah,  huzzah.  No longer able to resist the chanting
and promises of eternal coolness I donned my robe and installed my free copy.
</p>
        <p>
I clearly should have joined sooner.  Resharper has already changed my life. 
First it pointed that I had redundant overrides  in the control I was working
on, which I had really meant to delete. 
</p>
        <p>
Then it reminded me about the new <a href="http://msdn.microsoft.com/en-us/library/bb384061.aspx">implicit
type declaration</a> keyword var, so this...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">XmlDocument SomeDoc = new XmlDocument();</font>
          </p>
        </blockquote>
        <p>
becomes...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">var SomeDoc = new XmlDocument();</font>
          </p>
        </blockquote>
        <p>
Granted, that's not too exciting, but if your type declaration is something like...
</p>
        <blockquote>
          <font face="Courier New" color="#0000ff">Dictionary&lt;SomeStrangeType,ANamespace.AnotherLongType&gt;
SomeDictionary = new Dictionary&lt;SomeStrangeType,ANamespace.AnotherLongType&gt;();</font>
        </blockquote>
        <p>
with var it becomes...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">var SomeDictionary = new Dictionary&lt;SomeStrangeType,ANamespace.AnotherLongType&gt;();</font>
          </p>
        </blockquote>
        <p>
Then Resharper pointed out something I didn't realize was available in C#, the <a href="http://msdn.microsoft.com/en-us/library/bb384062.aspx">object
intializer</a>?? VB.NET has long had something similar with the <a href="http://msdn.microsoft.com/en-us/library/wc500chb.aspx">With
statement</a> (now with <a href="http://msdn.microsoft.com/en-us/library/bb385125.aspx">object
initializer goodness</a> too).  What's nice about this is that it saves repeating
the instance name in front of the properties.  So this...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">var MenuBinding = new MenuItemBinding(); 
<br />
MenuBinding.DataMember = MenuItemElementName; 
<br />
MenuBinding.TextField = DisplayTextAttribute; 
<br />
MenuBinding.NavigateUrlField = NavigationUrlAttribute; 
<br />
MenuBinding.Depth = Depth;</font>
          </p>
        </blockquote>
        <p>
becomes...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">var MenuBinding = new MenuItemBinding 
<br />
  { 
<br />
     DataMember = MenuItemElementName, 
<br />
     TextField = DisplayTextAttribute, 
<br />
     NavigateUrlField = NavigationUrlAttribute, 
<br />
     Depth = Depth 
<br />
  };</font>
          </p>
        </blockquote>
        <p>
I was staring at this new construct when I realized that -- it shouldn't work. The
project I was working on was a Framework 2.0 project and these things were in 3.0
syntax.  But the darn thing compiles and works.  Not even a single warning. 
WTF?  It turns out that since 3.0 and 3.5 are based on 2.0, these are simply
compiler tricks -- there is nothing fundamentally different about the types. 
Here's a <a href="http://weblogs.asp.net/shahar/archive/2008/01/23/use-c-3-features-from-c-2-and-net-2-0-code.aspx">blog
post</a> that explores in more detail what is happening under the covers.
</p>
        <p>
Not bad for 15 minutes of tooling around.  Guess I am an official member. Where's
the Koolaid?
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5ebf2926-8003-4c16-b328-8e91755317b0" />
      </body>
      <title>Sharpening Knives</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,5ebf2926-8003-4c16-b328-8e91755317b0.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,5ebf2926-8003-4c16-b328-8e91755317b0.aspx</link>
      <pubDate>Wed, 11 Jun 2008 03:24:01 GMT</pubDate>
      <description>&lt;p&gt;
The Resharper cult members already know this, but for those who haven't joined yet,
version &lt;a href="http://www.jetbrains.com/resharper/download/"&gt;4.0 released today&lt;/a&gt; with
VS 2008 support -- huzzah,&amp;#160; huzzah.&amp;#160; No longer able to resist the chanting
and promises of eternal coolness I donned my robe and installed my free copy.
&lt;/p&gt;
&lt;p&gt;
I clearly should have joined sooner.&amp;#160; Resharper has already changed my life.&amp;#160;
First it pointed that I had redundant overrides&amp;#160; in the control I was working
on, which I had really meant to delete. 
&lt;/p&gt;
&lt;p&gt;
Then it reminded me about the new &lt;a href="http://msdn.microsoft.com/en-us/library/bb384061.aspx"&gt;implicit
type declaration&lt;/a&gt; keyword var, so this...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;XmlDocument SomeDoc = new XmlDocument();&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
becomes...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;var SomeDoc = new XmlDocument();&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Granted, that's not too exciting, but if your type declaration is something like...
&lt;/p&gt;
&lt;blockquote&gt;&lt;font face="Courier New" color="#0000ff"&gt;Dictionary&amp;lt;SomeStrangeType,ANamespace.AnotherLongType&amp;gt;
SomeDictionary = new Dictionary&amp;lt;SomeStrangeType,ANamespace.AnotherLongType&amp;gt;();&lt;/font&gt; &lt;/blockquote&gt; 
&lt;p&gt;
with var it becomes...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;var SomeDictionary = new Dictionary&amp;lt;SomeStrangeType,ANamespace.AnotherLongType&amp;gt;();&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Then Resharper pointed out something I didn't realize was available in C#, the &lt;a href="http://msdn.microsoft.com/en-us/library/bb384062.aspx"&gt;object
intializer&lt;/a&gt;?? VB.NET has long had something similar with the &lt;a href="http://msdn.microsoft.com/en-us/library/wc500chb.aspx"&gt;With
statement&lt;/a&gt; (now with &lt;a href="http://msdn.microsoft.com/en-us/library/bb385125.aspx"&gt;object
initializer goodness&lt;/a&gt; too).&amp;#160; What's nice about this is that it saves repeating
the instance name in front of the properties.&amp;#160; So this...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;var MenuBinding = new MenuItemBinding(); 
&lt;br /&gt;
MenuBinding.DataMember = MenuItemElementName; 
&lt;br /&gt;
MenuBinding.TextField = DisplayTextAttribute; 
&lt;br /&gt;
MenuBinding.NavigateUrlField = NavigationUrlAttribute; 
&lt;br /&gt;
MenuBinding.Depth = Depth;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
becomes...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;var MenuBinding = new MenuItemBinding 
&lt;br /&gt;
&amp;#160; { 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; DataMember = MenuItemElementName, 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; TextField = DisplayTextAttribute, 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; NavigateUrlField = NavigationUrlAttribute, 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160; Depth = Depth 
&lt;br /&gt;
&amp;#160; };&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I was staring at this new construct when I realized that -- it shouldn't work. The
project I was working on was a Framework 2.0 project and these things were in 3.0
syntax.&amp;#160; But the darn thing compiles and works.&amp;#160; Not even a single warning.&amp;#160;
WTF?&amp;#160; It turns out that since 3.0 and 3.5 are based on 2.0, these are simply
compiler tricks -- there is nothing fundamentally different about the types.&amp;#160;
Here's a &lt;a href="http://weblogs.asp.net/shahar/archive/2008/01/23/use-c-3-features-from-c-2-and-net-2-0-code.aspx"&gt;blog
post&lt;/a&gt; that explores in more detail what is happening under the covers.
&lt;/p&gt;
&lt;p&gt;
Not bad for 15 minutes of tooling around.&amp;#160; Guess I am an official member. Where's
the Koolaid?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5ebf2926-8003-4c16-b328-8e91755317b0" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,5ebf2926-8003-4c16-b328-8e91755317b0.aspx</comments>
      <category>.NET</category>
      <category>2.0</category>
      <category>3.0</category>
      <category>3.5</category>
      <category>Resharper</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=3678a9bf-aeec-41a9-8041-e25671bd5fb5</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,3678a9bf-aeec-41a9-8041-e25671bd5fb5.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,3678a9bf-aeec-41a9-8041-e25671bd5fb5.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=3678a9bf-aeec-41a9-8041-e25671bd5fb5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Every month or so, someone posts a question on one of the .NET forums I frequent asking
if such and such will work, or if you can do so and so. The post will detail the background
of the issue, including theoretical approaches, possible drawbacks, imaginary contingencies
and tangential concepts.  Invariably the poster wants to know the "proper
way" to code something, and yet 6 paragraphs later hasn't shown what he or she
has already attempted.
</p>
        <p>
Why?
</p>
        <p>
Because the poster <em>hasn't written any code yet</em>.  
</p>
        <p>
Philosophical development discussions can be fun. Reviewing fundamental design issues,
or exploring the possibilities of a new technology or entering a new problem space
beg for "what if" questions. It's good to have an idea where to go, a vague
notion how to get there and to find out how others attempted the journey.  
Those are fun questions to answer.
</p>
        <p>
Another excellent time to ask "what if" questions is when facing an irrevocable
upgrade or configuration change.  When a wrong step can wreak havoc it wise to
ask for advice. That's what a forum is for -- to get pointed in the right direction
or pushed back on course or to be told to hurry back to shore. 
</p>
        <p>
No, what makes a coding "what if" question a total waste of time and bandwidth
is when it asks how to write a relatively small amount of code. The post itself is
longer than the most convoluted possible solution. To put it programmatically...
</p>
        <blockquote>
          <p>
            <font face="Courier New" color="#0000ff">
              <strong>if(Post.Length &gt; Code_Needed_To_See_If_It_Works.Length) 
<br />
    WasteOfTimeAndBandwidth();</strong>
            </font>
          </p>
        </blockquote>
        <p>
In other words, if the poster had actually tried to code one of the carefully penned
theoretical approaches, he or she would have ended up typing a lot less and would
have discovered the solution without a trip to forum land.  
</p>
        <p>
Some examples (and I wish I were making these up):
</p>
        <ul>
          <li>
Is it possible to set SomeObject.SomeProperty = SomeValue? 
</li>
          <li>
Can I put this control inside this other control? 
</li>
          <li>
How long will SomeObject.SomeMethod() take to run? 
</li>
        </ul>
        <p>
Programming is a wonderfully empirical undertaking. With IDEs (Integrated Development
Environments such as Visual Studio) it is easy to create code and test it.  At
the level of of a function or even a web page or windows form, there is no need for
thought experiments or theoretical ponderings -- the code either does what it is supposed
to or it doesn't.  There is no need to write <em>about</em> it -- just write
it.  If it doesn't work, then you can post a question that is based on something
real.
</p>
        <p>
Unless you are doing something silly like working on a production system, the cost
for trying something out is minimal.  In the worst cases, bad code throws an
error or just doesn't work.  Things don't explode, no one dies.  With source
code/version control (which everyone should get into the habit of using), it is trivial
to roll back to a previous working version.  
</p>
        <p>
So please, for your sake and Pete's, try it first.  See what happens.  You'll
save some time and might be pleasantly surprised. 
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=3678a9bf-aeec-41a9-8041-e25671bd5fb5" />
      </body>
      <title>For Pete's Sake -- Just Try It</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,3678a9bf-aeec-41a9-8041-e25671bd5fb5.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,3678a9bf-aeec-41a9-8041-e25671bd5fb5.aspx</link>
      <pubDate>Fri, 06 Jun 2008 00:59:09 GMT</pubDate>
      <description>&lt;p&gt;
Every month or so, someone posts a question on one of the .NET forums I frequent asking
if such and such will work, or if you can do so and so. The post will detail the background
of the issue, including theoretical approaches, possible drawbacks, imaginary contingencies
and tangential concepts.&amp;#160; Invariably the poster wants to know the &amp;quot;proper
way&amp;quot; to code something, and yet 6 paragraphs later hasn't shown what he or she
has already attempted.
&lt;/p&gt;
&lt;p&gt;
Why?
&lt;/p&gt;
&lt;p&gt;
Because the poster &lt;em&gt;hasn't written any code yet&lt;/em&gt;.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Philosophical development discussions can be fun. Reviewing fundamental design issues,
or exploring the possibilities of a new technology or entering a new problem space
beg for &amp;quot;what if&amp;quot; questions. It's good to have an idea where to go, a vague
notion how to get there and to find out how others attempted the journey.&amp;#160;&amp;#160;
Those are fun questions to answer.
&lt;/p&gt;
&lt;p&gt;
Another excellent time to ask &amp;quot;what if&amp;quot; questions is when facing an irrevocable
upgrade or configuration change.&amp;#160; When a wrong step can wreak havoc it wise to
ask for advice. That's what a forum is for -- to get pointed in the right direction
or pushed back on course or to be told to hurry back to shore. 
&lt;/p&gt;
&lt;p&gt;
No, what makes a coding &amp;quot;what if&amp;quot; question a total waste of time and bandwidth
is when it asks how to write a relatively small amount of code. The post itself is
longer than the most convoluted possible solution. To put it programmatically...
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" color="#0000ff"&gt;&lt;strong&gt;if(Post.Length &amp;gt; Code_Needed_To_See_If_It_Works.Length) 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; WasteOfTimeAndBandwidth();&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
In other words, if the poster had actually tried to code one of the carefully penned
theoretical approaches, he or she would have ended up typing a lot less and would
have discovered the solution without a trip to forum land.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Some examples (and I wish I were making these up):
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Is it possible to set SomeObject.SomeProperty = SomeValue? 
&lt;/li&gt;
&lt;li&gt;
Can I put this control inside this other control? 
&lt;/li&gt;
&lt;li&gt;
How long will SomeObject.SomeMethod() take to run? 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Programming is a wonderfully empirical undertaking. With IDEs (Integrated Development
Environments such as Visual Studio) it is easy to create code and test it.&amp;#160; At
the level of of a function or even a web page or windows form, there is no need for
thought experiments or theoretical ponderings -- the code either does what it is supposed
to or it doesn't.&amp;#160; There is no need to write &lt;em&gt;about&lt;/em&gt; it -- just write
it.&amp;#160; If it doesn't work, then you can post a question that is based on something
real.
&lt;/p&gt;
&lt;p&gt;
Unless you are doing something silly like working on a production system, the cost
for trying something out is minimal.&amp;#160; In the worst cases, bad code throws an
error or just doesn't work.&amp;#160; Things don't explode, no one dies.&amp;#160; With source
code/version control (which everyone should get into the habit of using), it is trivial
to roll back to a previous working version.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So please, for your sake and Pete's, try it first.&amp;#160; See what happens.&amp;#160; You'll
save some time and might be pleasantly surprised. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=3678a9bf-aeec-41a9-8041-e25671bd5fb5" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,3678a9bf-aeec-41a9-8041-e25671bd5fb5.aspx</comments>
      <category>Annoyances</category>
      <category>Da Basics</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=369f1932-9d69-44b0-8c67-658043294cf5</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,369f1932-9d69-44b0-8c67-658043294cf5.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,369f1932-9d69-44b0-8c67-658043294cf5.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=369f1932-9d69-44b0-8c67-658043294cf5</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Received a surprised IM this morning from Jeff Schoolcraft, Code Camp Organizer Extraordinaire
and sometime <a href="http://thequeue.net/blog/default.aspx">blogger</a>.  
He was struck dumb by the fact that I  actually used the online editor to pen
my blogs.  He tried very hard not to question both my sanity and intelligence
when I told him that the #2 pencil was my first choice but it only updated my monitor.
</p>
        <p>
He patiently explained to me that there was a pretty nifty desktop tool available
and it was free.  He even sent me a <a href="http://get.live.com/writer/overview">link</a> to
download it. 
</p>
        <p>
So I installed <strong>Windows Live Writer</strong> and am taking it for a spin. So
far, so good. Much more space to work with, a nice clean interface and no worries
that my connection is going to die or my blog app is going to recycle while I am writing
an overlong post. 
</p>
        <p>
If you are reading this, it means that it posted successfully.
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=369f1932-9d69-44b0-8c67-658043294cf5" />
      </body>
      <title>More Navel Gazing</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,369f1932-9d69-44b0-8c67-658043294cf5.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,369f1932-9d69-44b0-8c67-658043294cf5.aspx</link>
      <pubDate>Fri, 30 May 2008 01:31:20 GMT</pubDate>
      <description>&lt;p&gt;
Received a surprised IM this morning from Jeff Schoolcraft, Code Camp Organizer Extraordinaire
and sometime &lt;a href="http://thequeue.net/blog/default.aspx"&gt;blogger&lt;/a&gt;.&amp;nbsp;&amp;nbsp;
He was struck dumb by the fact that I&amp;nbsp; actually used the online editor to pen
my blogs.&amp;nbsp; He tried very hard not to question both my sanity and intelligence
when I told him that the #2 pencil was my first choice but it only updated my monitor.
&lt;/p&gt;
&lt;p&gt;
He patiently explained to me that there was a pretty nifty desktop tool available
and it was free.&amp;nbsp; He even sent me a &lt;a href="http://get.live.com/writer/overview"&gt;link&lt;/a&gt; to
download it.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So I installed &lt;strong&gt;Windows Live Writer&lt;/strong&gt; and am taking it for a spin. So
far, so good. Much more space to work with, a nice clean interface and no worries
that my connection is going to die or my blog app is going to recycle while I am writing
an overlong post.&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
If you are reading this, it means that it posted successfully.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=369f1932-9d69-44b0-8c67-658043294cf5" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,369f1932-9d69-44b0-8c67-658043294cf5.aspx</comments>
      <category>dasBlog</category>
      <category>Live Writer</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=0f4be836-38ff-4e93-a29b-4282e979372c</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,0f4be836-38ff-4e93-a29b-4282e979372c.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,0f4be836-38ff-4e93-a29b-4282e979372c.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=0f4be836-38ff-4e93-a29b-4282e979372c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I hate upgrades.  I usually put them off until:
</p>
        <ol>
          <li>
Something (someone) puts a gun to my head</li>
          <li>
There is a compelling feature available</li>
          <li>
I'm feeling lucky<br /></li>
        </ol>
        <p>
Case 1 is the usual situation.  When things won't work any more, I'll bite the
bullet.  If things are working, I have a tendency to leave them alone because
vast experience has taught me that the Law of Unintended Consequences usually makes
itself known whenever something gets upgraded.  I don't care how many versions
behind it is.  I don't like to blow half a day getting back to where I was before
the upgrade.
</p>
        <p>
 
</p>
        <p>
Case 2 actually popped up twice in the last month.  I moved to Vista finally
because I wanted to play with the new PeerToPeer.Collaboration namespace in 3.5. 
It hasn't been too horrible, (except for the file search function which is even more
obtuse than it was in XP -- which I thought was an impossibility).  It was also
just a move to a fresh machine.  I also upgraded my <a href="http://www.thycotic.com/products_secretserver_overview.html"> my
password management software</a> (SecretServer) install, because I wanted to take
advantage of the ActiveDirectory feature.  I was only 3 major versions, 2 minor
versions and 30 revisions behind, but with some help from the good support folks at
Thycotic I was able to get it current without too much hassle.
</p>
        <p>
 
</p>
        <p>
Case 3 is something I should avoid.  I should know better, but it happened while
I fooling around with this blog last week.  I realized that the blog software
(<a href="http://www.dasblog.info/">dasBlog</a>) was many versions behind and I figured
the last upgrade hadn't been too bad.  There were also a couple quirks I figured
would be handled by the new version.  So  I downloaded all the new stuff,
merged my web.config file, made the few other changes and pushed everything up. 
Worked, mostly.  I couldn't edit or enter new entries.  The FreeTextBox
component was displaying a "was not installed correctly" error.  Hours of googling,
typing, begging and swearing later still no luck.
</p>
        <p>
 
</p>
        <p>
So tonight I decided it was time to move on.  dasBlog supports other editors,
and John Forsythe has created <a href="http://preview.tinyurl.com/6br7kt">a lovely
little addin</a> for the <a href="http://tinymce.moxiecode.com/">TinyMCE</a> rich
text editor.  I downloaded, uploaded, recycled the app, changed the configuration
and behold my dasBlog install once again is back where it was a week ago -- I have
a text editor to create entries.
</p>
        <p>
 
</p>
        <p>
On the positive side, TinyMCE is has more features and the new dasBlog goodies are
nice, so I guess it was a worthwhile exercise.  I'm just posting this to remind
myself that I should "never feel lucky" when considering an upgrade.
</p>
        <p>
 
</p>
        <p>
          <strong>UPDATE:</strong>  Just discovered Comments weren't working because I
had the Resolve IP Setting turned on. Looks good now. Not that I get lots of comments,
but I would like to provide the outlet.
</p>
        <p>
 
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=0f4be836-38ff-4e93-a29b-4282e979372c" />
      </body>
      <title>Something (Kinda) New </title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,0f4be836-38ff-4e93-a29b-4282e979372c.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,0f4be836-38ff-4e93-a29b-4282e979372c.aspx</link>
      <pubDate>Thu, 29 May 2008 02:22:05 GMT</pubDate>
      <description>&lt;p&gt;
I hate upgrades.&amp;nbsp; I usually put them off until:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Something (someone) puts a gun to my head&lt;/li&gt;
&lt;li&gt;
There is a compelling feature available&lt;/li&gt;
&lt;li&gt;
I'm feeling lucky&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Case 1 is the usual situation.&amp;nbsp; When things won't work any more, I'll bite the
bullet.&amp;nbsp; If things are working, I have a tendency to leave them alone because
vast experience has taught me that the Law of Unintended Consequences usually makes
itself known whenever something gets upgraded.&amp;nbsp; I don't care how many versions
behind it is.&amp;nbsp; I don't like to blow half a day getting back to where I was before
the upgrade.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Case 2 actually popped up twice in the last month.&amp;nbsp; I moved to Vista finally
because I wanted to play with the new PeerToPeer.Collaboration namespace in 3.5.&amp;nbsp;
It hasn't been too horrible, (except for the file search function which is even more
obtuse than it was in XP -- which I thought was an impossibility).&amp;nbsp; It was also
just a move to a fresh machine.&amp;nbsp; I also upgraded my &lt;a href="http://www.thycotic.com/products_secretserver_overview.html"&gt; my
password management software&lt;/a&gt; (SecretServer) install, because I wanted to take
advantage of the ActiveDirectory feature.&amp;nbsp; I was only 3 major versions, 2 minor
versions and 30 revisions behind, but with some help from the good support folks at
Thycotic I was able to get it current without too much hassle.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Case 3 is something I should avoid.&amp;nbsp; I should know better, but it happened while
I fooling around with this blog last week.&amp;nbsp; I realized that the blog software
(&lt;a href="http://www.dasblog.info/"&gt;dasBlog&lt;/a&gt;) was many versions behind and I figured
the last upgrade hadn't been too bad.&amp;nbsp; There were also a couple quirks I figured
would be handled by the new version.&amp;nbsp; So&amp;nbsp; I downloaded all the new stuff,
merged my web.config file, made the few other changes and pushed everything up.&amp;nbsp;
Worked, mostly.&amp;nbsp; I couldn't edit or enter new entries.&amp;nbsp; The FreeTextBox
component was displaying a "was not installed correctly" error.&amp;nbsp; Hours of googling,
typing, begging and swearing later still no luck.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So tonight I decided it was time to move on.&amp;nbsp; dasBlog supports other editors,
and John Forsythe has created &lt;a href="http://preview.tinyurl.com/6br7kt"&gt;a lovely
little addin&lt;/a&gt; for the &lt;a href="http://tinymce.moxiecode.com/"&gt;TinyMCE&lt;/a&gt; rich
text editor.&amp;nbsp; I downloaded, uploaded, recycled the app, changed the configuration
and behold my dasBlog install once again is back where it was a week ago -- I have
a text editor to create entries.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
On the positive side, TinyMCE is has more features and the new dasBlog goodies are
nice, so I guess it was a worthwhile exercise.&amp;nbsp; I'm just posting this to remind
myself that I should "never feel lucky" when considering an upgrade.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;UPDATE:&lt;/strong&gt;&amp;nbsp; Just discovered Comments weren't working because I
had the Resolve IP Setting turned on. Looks good now. Not that I get lots of comments,
but I would like to provide the outlet.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=0f4be836-38ff-4e93-a29b-4282e979372c" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,0f4be836-38ff-4e93-a29b-4282e979372c.aspx</comments>
      <category>Annoyances</category>
      <category>dasBlog</category>
    </item>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=7f00c831-3534-491e-be8d-4993f8cd770a</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,7f00c831-3534-491e-be8d-4993f8cd770a.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,7f00c831-3534-491e-be8d-4993f8cd770a.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=7f00c831-3534-491e-be8d-4993f8cd770a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">While crawling around in VS 2008 to work
on the <a href="http://www.vpsw.com/blogbaby/PermaLink,guid,cd94d8d1-fdda-4a14-8549-2f597a593660.aspx">P2P
presentation</a> for <a href="http://www.rocknug.org">RockNUG</a> and the <a href="http://novacodecamp.org">NOVA
Code Camp</a>, I stumbled upon a lovely little feature under Intellisense on the Edit
menu called <a href="http://msdn.microsoft.com/en-us/library/bb514114.aspx">Organize
Usings</a>.  A simple click can remove unused using statements, sort the statements
or do both.  Cleans up code faster than a life style diva on a nicotine binge.<br /><br />
Visual Studio has default templates for all project items and they frequently includes
using statements for namespaces, that well, never get used.  The class template,
for example really, really wants you to use the <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx">LINQ</a> and
the System.Text namespaces. If you haven't gotten around to <a href="http://msdn.microsoft.com/en-us/library/ms247119.aspx">modifying
the default templates</a>, you'll have lots of unneeded using statements cluttering
up your code.  The Organize Usings feature can help save other developers (or
the future you) from wondering, "Where the heck did he use LINQ in this class?".<br /><br />
And just so you don't strain yourself, it is only available for C#.<br /><br /><br /><p></p><img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=7f00c831-3534-491e-be8d-4993f8cd770a" /></body>
      <title>Making Like Martha Stewart</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,7f00c831-3534-491e-be8d-4993f8cd770a.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,7f00c831-3534-491e-be8d-4993f8cd770a.aspx</link>
      <pubDate>Mon, 19 May 2008 16:52:34 GMT</pubDate>
      <description>While crawling around in VS 2008 to work on the &lt;a href="http://www.vpsw.com/blogbaby/PermaLink,guid,cd94d8d1-fdda-4a14-8549-2f597a593660.aspx"&gt;P2P
presentation&lt;/a&gt; for &lt;a href="http://www.rocknug.org"&gt;RockNUG&lt;/a&gt; and the &lt;a href="http://novacodecamp.org"&gt;NOVA
Code Camp&lt;/a&gt;, I stumbled upon a lovely little feature under Intellisense on the Edit
menu called &lt;a href="http://msdn.microsoft.com/en-us/library/bb514114.aspx"&gt;Organize
Usings&lt;/a&gt;.&amp;nbsp; A simple click can remove unused using statements, sort the statements
or do both.&amp;nbsp; Cleans up code faster than a life style diva on a nicotine binge.&lt;br&gt;
&lt;br&gt;
Visual Studio has default templates for all project items and they frequently includes
using statements for namespaces, that well, never get used.&amp;nbsp; The class template,
for example really, really wants you to use the &lt;a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx"&gt;LINQ&lt;/a&gt; and
the System.Text namespaces. If you haven't gotten around to &lt;a href="http://msdn.microsoft.com/en-us/library/ms247119.aspx"&gt;modifying
the default templates&lt;/a&gt;, you'll have lots of unneeded using statements cluttering
up your code.&amp;nbsp; The Organize Usings feature can help save other developers (or
the future you) from wondering, "Where the heck did he use LINQ in this class?".&lt;br&gt;
&lt;br&gt;
And just so you don't strain yourself, it is only available for C#.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=7f00c831-3534-491e-be8d-4993f8cd770a" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,7f00c831-3534-491e-be8d-4993f8cd770a.aspx</comments>
      <category>3.5</category>
      <category>Visual Studio 2008</category>
    </item>
  </channel>
</rss>
