<?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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=static-methods-are-death-to-testability</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Thu, 19 Jan 2012 16:42:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: David Zentgraf</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-16200</link>
		<dc:creator>David Zentgraf</dc:creator>
		<pubDate>Thu, 05 Jan 2012 04:28:58 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-16200</guid>
		<description>Static functions are only problematic if they have unseen dependencies (violate dependency injection principles) and are not idempotent (have state). It&#039;s not even about being leaf methods, that&#039;s just a recursive problem of my first sentence. Static methods are just functions. Functions are extremely easy to test if they&#039;re idempotent. That&#039;s the functional principle. Functions may call other functions as much as they like and it doesn&#039;t change anything about their being idempotent, as long as the functions they call are also idempotent. You can have a long chain of function calls hanging off of your static method, if none of them have any state there&#039;s no problem. That&#039;s why Math.abs() is easy to test, because it adheres to these principles. In the background it may make a thousand calls to hundreds of different functions, you don&#039;t need to care.

So your rant against static methods is really a straw man rant against non-idempotent global functions, hence global state. It has nothing to do with being static. Static functions are fine and useful in OOP.</description>
		<content:encoded><![CDATA[<p>Static functions are only problematic if they have unseen dependencies (violate dependency injection principles) and are not idempotent (have state). It&#8217;s not even about being leaf methods, that&#8217;s just a recursive problem of my first sentence. Static methods are just functions. Functions are extremely easy to test if they&#8217;re idempotent. That&#8217;s the functional principle. Functions may call other functions as much as they like and it doesn&#8217;t change anything about their being idempotent, as long as the functions they call are also idempotent. You can have a long chain of function calls hanging off of your static method, if none of them have any state there&#8217;s no problem. That&#8217;s why Math.abs() is easy to test, because it adheres to these principles. In the background it may make a thousand calls to hundreds of different functions, you don&#8217;t need to care.</p>
<p>So your rant against static methods is really a straw man rant against non-idempotent global functions, hence global state. It has nothing to do with being static. Static functions are fine and useful in OOP.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MB</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-13029</link>
		<dc:creator>MB</dc:creator>
		<pubDate>Thu, 01 Dec 2011 05:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-13029</guid>
		<description>http://code.google.com/p/powermock/</description>
		<content:encoded><![CDATA[<p><a href="http://code.google.com/p/powermock/" rel="nofollow">http://code.google.com/p/powermock/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Static Methods: Time to Hit Rock Bottom &#124; DaedTech</title>
		<link>http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/comment-page-1/#comment-11800</link>
		<dc:creator>Static Methods: Time to Hit Rock Bottom &#124; DaedTech</dc:creator>
		<pubDate>Tue, 01 Nov 2011 16:54:02 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=352#comment-11800</guid>
		<description>[...] They kill testability of code bases. Misko Hevery agrees. [...]</description>
		<content:encoded><![CDATA[<p>[...] They kill testability of code bases. Misko Hevery agrees. [...]</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

