<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comments on: Enforce Correct Usage By Wrapping Types</title>
	<atom:link href="http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=enforce-correct-usage-by-wrapping-types</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 09:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58138</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Thu, 15 Jul 2010 14:24:11 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58138</guid>
		<description>@John Sonmez

I see now you aren&#039;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#039;t the point here. Thanks for clearing that up with me.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>I see now you aren&#8217;t doing unit testing, you are doing integration testing and automation. I was trying to isolate components, which isn&#8217;t the point here. Thanks for clearing that up with me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-2/#comment-58137</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Thu, 15 Jul 2010 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58137</guid>
		<description>&lt;a href=&quot;#comment-58128&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.

The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.

Take a look at this for more information: http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</description>
		<content:encoded><![CDATA[<p><a href="#comment-58128" rel="nofollow">@Bryan Watts</a><br />
The problem is the actual running system that is under test is using the real system time.  Even though you could make a synthetic time, it would not be accurate for the kind of tests the test code is testing.</p>
<p>The test code in this case is driving a Watij library which is driving a web browser to directly test the web pages, therefore the tests need to be able to operate against the current system.</p>
<p>Take a look at this for more information: <a href="http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing" rel="nofollow">http://www.slideshare.net/jsonmez/internal-ds-ls-for-automated-functional-testing</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58128</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 22:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58128</guid>
		<description>@John Sonmez

No worries, just making sure we are on the same page.

Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#039;t be valid next month?</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>No worries, just making sure we are on the same page.</p>
<p>Is it correct to say that you are using DateTime.Now directly in your code, and that is the reason why the tests won&#8217;t be valid next month?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58127</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58127</guid>
		<description>&lt;a href=&quot;#comment-58126&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
You are right, I never really explained that part.

In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.

Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58126" rel="nofollow">@Bryan Watts</a><br />
You are right, I never really explained that part.</p>
<p>In that example, the problem would be that you can only run future eligibility months on the system, not past ones.  So if you hard coded dates for creating a case for July 2010, and a 19 year old person, next month the test would not work.</p>
<p>Let me know if that makes it clear now.  Sorry, I assumed too much domain knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58126</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 21:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58126</guid>
		<description>@John Sonmez

Hi John,

I guess I don&#039;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?

I am unclear on the requirement &quot;I need the ages and application dates to be able to move up with the real time&quot;, which is probably why I am having difficulty understanding your position.</description>
		<content:encoded><![CDATA[<p>@John Sonmez</p>
<p>Hi John,</p>
<p>I guess I don&#8217;t see where in your post you explain why hard-coded dates are undesirable. I understand your reasoning from that point forward, but I am unclear as to how you got there. Perhaps you could elaborate on why you are avoiding hard-coded dates in the first place?</p>
<p>I am unclear on the requirement &#8220;I need the ages and application dates to be able to move up with the real time&#8221;, which is probably why I am having difficulty understanding your position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58123</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Wed, 14 Jul 2010 19:27:54 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58123</guid>
		<description>&lt;a href=&quot;#comment-58122&quot; rel=&quot;nofollow&quot;&gt;@Bryan Watts&lt;/a&gt; 
Hi Bryan,

I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.

In this case I was creating an API for automated functional testing through the API.

Let me give you an example and see if this clears up what I was talking about.

Lets supposed I needed to created a brand new application with 19 year old on it.

I need the application date to be the current month... so CaseDate.CurrentMonth

I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).

That test data will always be valid, regardless of the current year or time.

The idea is that the problem domain doesn&#039;t really care about specific dates, it cares about relative dates.

Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58122" rel="nofollow">@Bryan Watts</a><br />
Hi Bryan,</p>
<p>I understand what you are saying, but in this case I need the ages and application dates to be able to move up with the real time.</p>
<p>In this case I was creating an API for automated functional testing through the API.</p>
<p>Let me give you an example and see if this clears up what I was talking about.</p>
<p>Lets supposed I needed to created a brand new application with 19 year old on it.</p>
<p>I need the application date to be the current month&#8230; so CaseDate.CurrentMonth</p>
<p>I need the person to be 19 years old, so I use CaseDate.YearsAgo(19).</p>
<p>That test data will always be valid, regardless of the current year or time.</p>
<p>The idea is that the problem domain doesn&#8217;t really care about specific dates, it cares about relative dates.</p>
<p>Now, I agree with @Martin on not using DateTime in your code.  You can synthetically produce dates, but that is a different matter than what I am addressing here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bryan Watts</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58122</link>
		<dc:creator>Bryan Watts</dc:creator>
		<pubDate>Wed, 14 Jul 2010 18:54:48 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58122</guid>
		<description>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).

The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.

Were you to follow @Martin Jul&#039;s suggestion (which I favor as well), you would be able to declare the value of &quot;now&quot; for any given test. Hard-coded dates are then perfectly acceptable because &quot;now&quot; is hard-coded as well.

Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &quot;now&quot; value, which is the intent of the ITimestampProvider suggestion.

(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</description>
		<content:encoded><![CDATA[<p>It sounds like you are referencing DateTime.Now in your code, and since that value will change with different runs of the test fixture, hard-coded dates cannot represent fixed ages. (You imply this, but never state it, so let me know if that is an incorrect assessment).</p>
<p>The problem, then, is that you are unable to isolate the code being tested from the system clock. They are inherently coupled in such a way that all system clients must account for it. The CaseDate class merely treats the symptom, not the disease.</p>
<p>Were you to follow @Martin Jul&#8217;s suggestion (which I favor as well), you would be able to declare the value of &#8220;now&#8221; for any given test. Hard-coded dates are then perfectly acceptable because &#8220;now&#8221; is hard-coded as well.</p>
<p>Taking it further, what if you have a rule that takes effect in 2015, and you need to test it before it goes into production? Will you set your system clock ahead to run the test, and expect other devs to do the same? It makes more sense to abstract away the source of the &#8220;now&#8221; value, which is the intent of the ITimestampProvider suggestion.</p>
<p>(I realize this is not a use case of your system, but those kinds of rules are very relevant when giving general advice on handling dates.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Letrouit</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58116</link>
		<dc:creator>Julien Letrouit</dc:creator>
		<pubDate>Wed, 14 Jul 2010 12:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58116</guid>
		<description>John, it seems you are describing the &quot;value object&quot; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#039;s intent usage is. Which of the two below declaration tells more to the user of an API?

void SomeMethod(Decimal winProbability)

or

void SomeMethod(Probability winProbability)

In other words, you are not just &quot;forcing&quot; your API user, you are also helping him to understand your API.</description>
		<content:encoded><![CDATA[<p>John, it seems you are describing the &#8220;value object&#8221; pattern from DDD. So instead of a decimal, create a Probability struct, instead of a double, create a Money struct, and so on. The idea is the value object shields the underlying value with invariants. Doing that, you also are describing what this value&#8217;s intent usage is. Which of the two below declaration tells more to the user of an API?</p>
<p>void SomeMethod(Decimal winProbability)</p>
<p>or</p>
<p>void SomeMethod(Probability winProbability)</p>
<p>In other words, you are not just &#8220;forcing&#8221; your API user, you are also helping him to understand your API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58099</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 12 Jul 2010 13:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58099</guid>
		<description>&lt;a href=&quot;#comment-58095&quot; rel=&quot;nofollow&quot;&gt;@Rob&lt;/a&gt; 

Hi Rob, 

I think you are missing it.  caseDate.Date does not have a setter in my implementation.

The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.

This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</description>
		<content:encoded><![CDATA[<p><a href="#comment-58095" rel="nofollow">@Rob</a> </p>
<p>Hi Rob, </p>
<p>I think you are missing it.  caseDate.Date does not have a setter in my implementation.</p>
<p>The whole point is to make sure that raw dates are not used, instead one of the methods I provide on my custom date class is used to construct the date.</p>
<p>This prevents any dates from being hard-coded, since it is not possible to call the API without using the CaseDate class, and the date can not be set manually in the CaseDate class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Jul</title>
		<link>http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/comment-page-1/#comment-58097</link>
		<dc:creator>Martin Jul</dc:creator>
		<pubDate>Mon, 12 Jul 2010 08:47:58 +0000</pubDate>
		<guid isPermaLink="false">http://elegantcode.com/2010/07/11/enforce-correct-usage-by-wrapping-types/#comment-58097</guid>
		<description>I like your thinking on this. The CaseDate.YearsAgo(20) makes the code very readable.

However in order to make tests reproducible we normally use another solution for this problem. Rather than not accepting dates in the API we do not request dates in our code.

Instead, we always use an instance of an ITimestampProvider to get the date that we need. It has a method like GetUtcNow.

In most cases the tests inject a ConstantTimestampProvider that returns a constant time.
If we need time to pass, we can step the time forward on this stub.

This way we can easily control time and it it easy to verify that timestamps etc in the code are generated correctly, for example (vb.net):


dim justNow as new DateTime(2010,7,12)
dim timestampProvider as new ConstantTimestampProvider(justNow)

&#039; ....

Assert.That(actual.LastUpdatedAt, [Is].EqualTo(justNow))


Best regards,
Martin Jul

Clojure / .NET developer</description>
		<content:encoded><![CDATA[<p>I like your thinking on this. The CaseDate.YearsAgo(20) makes the code very readable.</p>
<p>However in order to make tests reproducible we normally use another solution for this problem. Rather than not accepting dates in the API we do not request dates in our code.</p>
<p>Instead, we always use an instance of an ITimestampProvider to get the date that we need. It has a method like GetUtcNow.</p>
<p>In most cases the tests inject a ConstantTimestampProvider that returns a constant time.<br />
If we need time to pass, we can step the time forward on this stub.</p>
<p>This way we can easily control time and it it easy to verify that timestamps etc in the code are generated correctly, for example (vb.net):</p>
<p>dim justNow as new DateTime(2010,7,12)<br />
dim timestampProvider as new ConstantTimestampProvider(justNow)</p>
<p>&#8216; &#8230;.</p>
<p>Assert.That(actual.LastUpdatedAt, [Is].EqualTo(justNow))</p>
<p>Best regards,<br />
Martin Jul</p>
<p>Clojure / .NET developer</p>
]]></content:encoded>
	</item>
</channel>
</rss>

