<?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: Root Cause of Singletons</title>
	<atom:link href="http://misko.hevery.com/2008/08/25/root-cause-of-singletons/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=root-cause-of-singletons</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: misko</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-7293</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Sun, 20 Mar 2011 07:52:23 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-7293</guid>
		<description>Hi Bhavin,

So you are correct in your analysis, but what you are describing is not global state.

1) Global-state means just that. &quot;state&quot; and if it is immutable, then it is not a &quot;state&quot; but rather a constant, and you are correct constants are fine.
2) Global method, while not ideal see: http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/ But again, it is not state, it is just global behavior.

I am referring to true global state, which is mutable.</description>
		<content:encoded><![CDATA[<p>Hi Bhavin,</p>
<p>So you are correct in your analysis, but what you are describing is not global state.</p>
<p>1) Global-state means just that. &#8220;state&#8221; and if it is immutable, then it is not a &#8220;state&#8221; but rather a constant, and you are correct constants are fine.<br />
2) Global method, while not ideal see: <a href="http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/" rel="nofollow">http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/</a> But again, it is not state, it is just global behavior.</p>
<p>I am referring to true global state, which is mutable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bhavin Kamani</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-7267</link>
		<dc:creator>Bhavin Kamani</dc:creator>
		<pubDate>Fri, 18 Mar 2011 12:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-7267</guid>
		<description>@misko

I agree that mutable global state is bad mainly for two reasons. 1) Since state can be changed, it creates a very vulnerable dependency among objects. 2) Testing becomes that much harder as you need to setup global state and isolation of global state is hard. 

However, IMO Global state that is either immutable or provides just a common set of behavior is not an anti-pattern. Reason no. 1 becomes irrelevant since there is no state changing happening and hence vulnerability disappears. Global State still needs to be setup before every unit test. However  isolation is not required.

In the case of Post.create, I guess its ok since it is just providing a behavior of inserting a record. 
However, areas within rails where one can change the global configurations on the fly are ugly. These are classic mutable Global state which should be eliminated with DI pattern.

Would love to hear your opinion :-)</description>
		<content:encoded><![CDATA[<p>@misko</p>
<p>I agree that mutable global state is bad mainly for two reasons. 1) Since state can be changed, it creates a very vulnerable dependency among objects. 2) Testing becomes that much harder as you need to setup global state and isolation of global state is hard. </p>
<p>However, IMO Global state that is either immutable or provides just a common set of behavior is not an anti-pattern. Reason no. 1 becomes irrelevant since there is no state changing happening and hence vulnerability disappears. Global State still needs to be setup before every unit test. However  isolation is not required.</p>
<p>In the case of Post.create, I guess its ok since it is just providing a behavior of inserting a record.<br />
However, areas within rails where one can change the global configurations on the fly are ugly. These are classic mutable Global state which should be eliminated with DI pattern.</p>
<p>Would love to hear your opinion <img src='http://misko.hevery.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-5452</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 23 Dec 2010 07:51:18 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-5452</guid>
		<description>@Andrzej,

yes, it is not valid. since it is accessing more then it &quot;friends&quot; the proper way would be to get postFactory injected into the constructor of the controller and then call postFactory.create().  But since Rails does not have a DI framework, it would be hard to do that in the current state of rails.</description>
		<content:encoded><![CDATA[<p>@Andrzej,</p>
<p>yes, it is not valid. since it is accessing more then it &#8220;friends&#8221; the proper way would be to get postFactory injected into the constructor of the controller and then call postFactory.create().  But since Rails does not have a DI framework, it would be hard to do that in the current state of rails.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrzej Krzywda</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-5446</link>
		<dc:creator>Andrzej Krzywda</dc:creator>
		<pubDate>Wed, 22 Dec 2010 23:15:43 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-5446</guid>
		<description>Yes, Rails itself is full of global state. 

What I actually meant with my question is whether this kind of &quot;pattern&quot; (static call to Post.create) is good or not. 

I assume that a Rails controller is an object as anything else. It should only talk to objects that are its &quot;friends&quot;. 

My opinion is that accessing the global class Post in this case is invalid. I was curious what&#039;s your opinion and if you have any recommendation how to replace it.

I believe this problem occurs also in other web frameworks.</description>
		<content:encoded><![CDATA[<p>Yes, Rails itself is full of global state. </p>
<p>What I actually meant with my question is whether this kind of &#8220;pattern&#8221; (static call to Post.create) is good or not. </p>
<p>I assume that a Rails controller is an object as anything else. It should only talk to objects that are its &#8220;friends&#8221;. </p>
<p>My opinion is that accessing the global class Post in this case is invalid. I was curious what&#8217;s your opinion and if you have any recommendation how to replace it.</p>
<p>I believe this problem occurs also in other web frameworks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-5442</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 22 Dec 2010 18:51:15 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-5442</guid>
		<description>@Andrzej,

The rails is loaded with global state. Which is one reason why rails could not be multithreaded. It also makes it hard to know how to assert and reset state in rails, but luckily they have done most of the hard work in the test suites, so rails is testable despite their reliance on the global state.</description>
		<content:encoded><![CDATA[<p>@Andrzej,</p>
<p>The rails is loaded with global state. Which is one reason why rails could not be multithreaded. It also makes it hard to know how to assert and reset state in rails, but luckily they have done most of the hard work in the test suites, so rails is testable despite their reliance on the global state.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrzej Krzywda</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-5440</link>
		<dc:creator>Andrzej Krzywda</dc:creator>
		<pubDate>Wed, 22 Dec 2010 18:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-5440</guid>
		<description>What is your opinion on typical Rails controllers implementations?

A typical action looks like this:

def create
  @post = Post.create(params[:post])
  redirect_to @post
end

Can we say that calling Post.create is actually using global state? Is it bad? Can we do it better?</description>
		<content:encoded><![CDATA[<p>What is your opinion on typical Rails controllers implementations?</p>
<p>A typical action looks like this:</p>
<p>def create<br />
  @post = Post.create(params[:post])<br />
  redirect_to @post<br />
end</p>
<p>Can we say that calling Post.create is actually using global state? Is it bad? Can we do it better?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Singletons : Is Anti-Pattern? &#171; Technical Jottings</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-2505</link>
		<dc:creator>Singletons : Is Anti-Pattern? &#171; Technical Jottings</dc:creator>
		<pubDate>Wed, 02 Dec 2009 07:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-2505</guid>
		<description>[...] in few cases and there are some &#8220;cleaner&#8221; ways of achieving singleton benefits.  Here, Misko clearly points that Singletons are useful when there is one way flow in the [...]</description>
		<content:encoded><![CDATA[<p>[...] in few cases and there are some &#8220;cleaner&#8221; ways of achieving singleton benefits.  Here, Misko clearly points that Singletons are useful when there is one way flow in the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Another Architectural Framework, But Why? &#171; shaun smith</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-928</link>
		<dc:creator>Another Architectural Framework, But Why? &#171; shaun smith</dc:creator>
		<pubDate>Wed, 29 Apr 2009 12:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-928</guid>
		<description>[...] standard Singleton implementation (that static getInstance method) is severely flawed. Unless you are writing device drivers, there is almost no excuse to touch a [...]</description>
		<content:encoded><![CDATA[<p>[...] standard Singleton implementation (that static getInstance method) is severely flawed. Unless you are writing device drivers, there is almost no excuse to touch a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to do Everything Wrong with Servlets</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-853</link>
		<dc:creator>How to do Everything Wrong with Servlets</dc:creator>
		<pubDate>Wed, 08 Apr 2009 18:43:29 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-853</guid>
		<description>[...] use global state and singletons for inter servlet communication (which we have covered in detailed here, here, and [...]</description>
		<content:encoded><![CDATA[<p>[...] use global state and singletons for inter servlet communication (which we have covered in detailed here, here, and [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AS3 Dependency Injection and [Autowire] &#171; shaun smith</title>
		<link>http://misko.hevery.com/2008/08/25/root-cause-of-singletons/comment-page-1/#comment-806</link>
		<dc:creator>AS3 Dependency Injection and [Autowire] &#171; shaun smith</dc:creator>
		<pubDate>Thu, 26 Mar 2009 11:42:09 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=192#comment-806</guid>
		<description>[...] Alternatively, you could use a Singleton to hang all your objects on. That would not be cool: link, link, link. [...]</description>
		<content:encoded><![CDATA[<p>[...] Alternatively, you could use a Singleton to hang all your objects on. That would not be cool: link, link, link. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

