<?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: Static Methods are Death to Testability</title>
	<atom:link href="http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 02 Sep 2010 04:05:01 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Puneet Monga</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-3598</link>
		<dc:creator>Puneet Monga</dc:creator>
		<pubDate>Tue, 08 Jun 2010 12:26:10 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-3598</guid>
		<description>Agreed with the following points in your blog:
1) Its procedural code
2) Nothing to wire
3) They have access to the global state of the application
4) It cannot be mocked.

However, please note that these points serve as &quot;donts&quot; while coding a static method.

1) Its procedural code : Not all the code always belong to some or the other class.
2) Nothing to wire: If you have something to wire inside the static method, it means that its high time that you revisit the implementation of this static method.
3) They have access to the global state of the application: High time again to revisit and redefine your static method
4) It cannot be mocked: If static method has to be mocked, its high time again to revisit and redefine your static method.

Purpose of static methods is to write more of utility kind of methods that takes an input, returns an output provided that it doesn&#039;t remember the state and doesn&#039;t depend on any external components. If you break these rules, that&#039;s a coding problem and not to blame static methods for the same.

Static methods that puts testability at risks means that static methods were not written they were supposed to be. 

That&#039;s also the case for instance (non-static) methods as well. If one is not aware of how to write non-static methods properly, then too it can put testability at risk.</description>
		<content:encoded><![CDATA[<p>Agreed with the following points in your blog:<br />
1) Its procedural code<br />
2) Nothing to wire<br />
3) They have access to the global state of the application<br />
4) It cannot be mocked.</p>
<p>However, please note that these points serve as &#8220;donts&#8221; while coding a static method.</p>
<p>1) Its procedural code : Not all the code always belong to some or the other class.<br />
2) Nothing to wire: If you have something to wire inside the static method, it means that its high time that you revisit the implementation of this static method.<br />
3) They have access to the global state of the application: High time again to revisit and redefine your static method<br />
4) It cannot be mocked: If static method has to be mocked, its high time again to revisit and redefine your static method.</p>
<p>Purpose of static methods is to write more of utility kind of methods that takes an input, returns an output provided that it doesn&#8217;t remember the state and doesn&#8217;t depend on any external components. If you break these rules, that&#8217;s a coding problem and not to blame static methods for the same.</p>
<p>Static methods that puts testability at risks means that static methods were not written they were supposed to be. </p>
<p>That&#8217;s also the case for instance (non-static) methods as well. If one is not aware of how to write non-static methods properly, then too it can put testability at risk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dotnetdave</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-3405</link>
		<dc:creator>dotnetdave</dc:creator>
		<pubDate>Mon, 26 Apr 2010 23:03:14 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-3405</guid>
		<description>Extension Methods are wonderful for customising your c# dev practices. So long as you don&#039;t mind wrapping your literal numbers in brackets, why not just use something like the following?

(-5).Abs()

public static int Abs(this int someNumber)
        {
            return Math.Abs(someNumber);
        }</description>
		<content:encoded><![CDATA[<p>Extension Methods are wonderful for customising your c# dev practices. So long as you don&#8217;t mind wrapping your literal numbers in brackets, why not just use something like the following?</p>
<p>(-5).Abs()</p>
<p>public static int Abs(this int someNumber)<br />
        {<br />
            return Math.Abs(someNumber);<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-3180</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Tue, 09 Mar 2010 04:29:26 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-3180</guid>
		<description>Hi Monoj,

My understanding of encapsulation is that only the object methods should interact with the state of the object. This is why a service object which has getters/setters breaks encapsulation. With regard to constructor I don&#039;t think it break encapsulation, as you are not allowed to modify the state of the object, you only need to provide the state/dependencies on creation. In addition the callee is does not know how to create the dependency, it asks for it likewise. 

Here is some more discussion I found online
http://stackoverflow.com/questions/1005473/must-dependency-injection-come-at-the-expense-of-encapsulation</description>
		<content:encoded><![CDATA[<p>Hi Monoj,</p>
<p>My understanding of encapsulation is that only the object methods should interact with the state of the object. This is why a service object which has getters/setters breaks encapsulation. With regard to constructor I don&#8217;t think it break encapsulation, as you are not allowed to modify the state of the object, you only need to provide the state/dependencies on creation. In addition the callee is does not know how to create the dependency, it asks for it likewise. </p>
<p>Here is some more discussion I found online<br />
<a href="http://stackoverflow.com/questions/1005473/must-dependency-injection-come-at-the-expense-of-encapsulation" rel="nofollow">http://stackoverflow.com/questions/1005473/must-dependency-injection-come-at-the-expense-of-encapsulation</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: manoj</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-3175</link>
		<dc:creator>manoj</dc:creator>
		<pubDate>Mon, 08 Mar 2010 11:41:42 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-3175</guid>
		<description>Hi,
with regards to this and also the article about Singletons, it seems to me that you are talking in general about code that has dependecy pull. e.g.
a Class X has a process() method that goes like {
     y = new YImpl();
     y.doIt();
}
So you have a problem with testing this method since calling process() is always calling YImpl, and this cannot be changed with some other implementation. So YImpl should have been explicitly passed to process() ?

But as we pass more and more parameters, does it not break encapsulation ? There could be problems related with improper use. So somebody may be able to pass an incorrect instance of creditcardprocessor that bypasses logging/auth ?</description>
		<content:encoded><![CDATA[<p>Hi,<br />
with regards to this and also the article about Singletons, it seems to me that you are talking in general about code that has dependecy pull. e.g.<br />
a Class X has a process() method that goes like {<br />
     y = new YImpl();<br />
     y.doIt();<br />
}<br />
So you have a problem with testing this method since calling process() is always calling YImpl, and this cannot be changed with some other implementation. So YImpl should have been explicitly passed to process() ?</p>
<p>But as we pass more and more parameters, does it not break encapsulation ? There could be problems related with improper use. So somebody may be able to pass an incorrect instance of creditcardprocessor that bypasses logging/auth ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-2720</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Sat, 02 Jan 2010 20:52:26 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-2720</guid>
		<description>The performance of using static vs instance method/variables is next to insignificant, so I would not use that as an argument. :-)</description>
		<content:encoded><![CDATA[<p>The performance of using static vs instance method/variables is next to insignificant, so I would not use that as an argument. <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Helltime for January 1 &#171; I Built His Cage</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-2712</link>
		<dc:creator>Helltime for January 1 &#171; I Built His Cage</dc:creator>
		<pubDate>Sat, 02 Jan 2010 01:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-2712</guid>
		<description>[...] The gist of the post is to use static members whenever you can for values that you know won&#8217;t change. There is a potentially significant performance boost, but I fear advice like this will lead monkeys to apply staticity to areas where it is inappropriate and doom their testing efforts. [...]</description>
		<content:encoded><![CDATA[<p>[...] The gist of the post is to use static members whenever you can for values that you know won&#8217;t change. There is a potentially significant performance boost, but I fear advice like this will lead monkeys to apply staticity to areas where it is inappropriate and doom their testing efforts. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Se hace camino al andar&#8230; &#187; Blog Archive &#187; Métodos estáticos y pruebas unitarias</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-2585</link>
		<dc:creator>Se hace camino al andar&#8230; &#187; Blog Archive &#187; Métodos estáticos y pruebas unitarias</dc:creator>
		<pubDate>Sun, 13 Dec 2009 22:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-2585</guid>
		<description>[...] para obtener información de contexto y, sobre todo, de la plataforma. Y me viene al pelo el reciente artículo de Misko Hevery donde explica por qué los métodos estáticos son tan malos para las pruebas y delatan diseños [...]</description>
		<content:encoded><![CDATA[<p>[...] para obtener información de contexto y, sobre todo, de la plataforma. Y me viene al pelo el reciente artículo de Misko Hevery donde explica por qué los métodos estáticos son tan malos para las pruebas y delatan diseños [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Principles, Patterns, and Practices of Mediocre Programming : Steve Smith's Blog</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-2045</link>
		<dc:creator>Principles, Patterns, and Practices of Mediocre Programming : Steve Smith's Blog</dc:creator>
		<pubDate>Thu, 08 Oct 2009 18:44:01 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-2045</guid>
		<description>[...] Static Methods are Death to Testability [...]</description>
		<content:encoded><![CDATA[<p>[...] Static Methods are Death to Testability [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-1804</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 02 Sep 2009 15:43:20 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-1804</guid>
		<description>@Heiko,

I know few functional languages, and while I am nowhere as versed in them nor have as much experience in OO, I do know, that many things are still the same. Instead of injecting classes you need to inject functions, and testability is still something you need to think about.

But these blog posts are not about functional languages! These blog posts are about OO languages. 

-- Misko</description>
		<content:encoded><![CDATA[<p>@Heiko,</p>
<p>I know few functional languages, and while I am nowhere as versed in them nor have as much experience in OO, I do know, that many things are still the same. Instead of injecting classes you need to inject functions, and testability is still something you need to think about.</p>
<p>But these blog posts are not about functional languages! These blog posts are about OO languages. </p>
<p>&#8211; Misko</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Heiko</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-1803</link>
		<dc:creator>Heiko</dc:creator>
		<pubDate>Wed, 02 Sep 2009 14:49:56 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-1803</guid>
		<description>Learn a functional language. Then you certainly will rewrite your post.</description>
		<content:encoded><![CDATA[<p>Learn a functional language. Then you certainly will rewrite your post.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
