<?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: Flaw: Brittle Global State &amp; Singletons</title>
	<atom:link href="http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com</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: Dave Abrahams</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-17377</link>
		<dc:creator>Dave Abrahams</dc:creator>
		<pubDate>Tue, 17 Jan 2012 14:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-17377</guid>
		<description>On  &quot;JVM global state&quot; vs. &quot;Application shared state,&quot; I agree there is a distinction but AFAICT it is only a matter of degree.  The more sharing in an application, the more likely it is that you&#039;ll need to use one &quot;sharer&quot; to set up conditions for another &quot;sharer&quot; to be tested.  Or, you might easily fail to test the real conditions of your application because of an interaction that&#039;s hidden in that shared, mutable state.</description>
		<content:encoded><![CDATA[<p>On  &#8220;JVM global state&#8221; vs. &#8220;Application shared state,&#8221; I agree there is a distinction but AFAICT it is only a matter of degree.  The more sharing in an application, the more likely it is that you&#8217;ll need to use one &#8220;sharer&#8221; to set up conditions for another &#8220;sharer&#8221; to be tested.  Or, you might easily fail to test the real conditions of your application because of an interaction that&#8217;s hidden in that shared, mutable state.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-8387</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Mon, 23 May 2011 19:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-8387</guid>
		<description>@andrea,

Service Container/Locator is still a global variable and hence it suffers all things related to global variables. We have DI, and DI solves this much better, so we are not forced to use Service Locator.</description>
		<content:encoded><![CDATA[<p>@andrea,</p>
<p>Service Container/Locator is still a global variable and hence it suffers all things related to global variables. We have DI, and DI solves this much better, so we are not forced to use Service Locator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yes</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-8291</link>
		<dc:creator>yes</dc:creator>
		<pubDate>Thu, 19 May 2011 17:50:00 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-8291</guid>
		<description>Hi Misko,

Do you think the Service Container is that bad? A function or a method where all our helper object instances are stored. 

http://symfony.com/doc/2.0/book/service_container.html

What do you think about it?

http://stackoverflow.com/questions/1812472/in-a-php-project-how-do-you-store-access-and-organize-your-helper-objects/1812499#1812499


Thanks you so much</description>
		<content:encoded><![CDATA[<p>Hi Misko,</p>
<p>Do you think the Service Container is that bad? A function or a method where all our helper object instances are stored. </p>
<p><a href="http://symfony.com/doc/2.0/book/service_container.html" rel="nofollow">http://symfony.com/doc/2.0/book/service_container.html</a></p>
<p>What do you think about it?</p>
<p><a href="http://stackoverflow.com/questions/1812472/in-a-php-project-how-do-you-store-access-and-organize-your-helper-objects/1812499#1812499" rel="nofollow">http://stackoverflow.com/questions/1812472/in-a-php-project-how-do-you-store-access-and-organize-your-helper-objects/1812499#1812499</a></p>
<p>Thanks you so much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Refactoring static calls and global variables from an object &#124; Alternate Illusion</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-3038</link>
		<dc:creator>Refactoring static calls and global variables from an object &#124; Alternate Illusion</dc:creator>
		<pubDate>Sat, 06 Feb 2010 12:12:46 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-3038</guid>
		<description>[...] What&#8217;s wrong with globals?  Accessing global state statically doesn’t clarify those shared dependencies to readers of the constructors and methods that use the Global State. Global State and Singletons make APIs lie about their true dependencies. To really understand the dependencies, developers must read every line of code. It causes Spooky Action at a Distance: when running test suites, global state mutated in one test can cause a subsequent or parallel test to fail unexpectedly. Misko Hevery: Flaw: Brittle Global State &amp; Singletons [...]</description>
		<content:encoded><![CDATA[<p>[...] What&#8217;s wrong with globals?  Accessing global state statically doesn’t clarify those shared dependencies to readers of the constructors and methods that use the Global State. Global State and Singletons make APIs lie about their true dependencies. To really understand the dependencies, developers must read every line of code. It causes Spooky Action at a Distance: when running test suites, global state mutated in one test can cause a subsequent or parallel test to fail unexpectedly. Misko Hevery: Flaw: Brittle Global State &amp; Singletons [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2993</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 28 Jan 2010 17:51:28 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2993</guid>
		<description>@David,

I am not proposing to have more instances or consume memory. Whether you write you application with Global state (Singleton) or with dependency injection (where you have single instance of a class). You have the same number of objects and hence the same memory consumption. The question at the table is not how many instances of objects you have as that is fixed by the application design, but how do these objects get to where they need to be: 1) Global state (bad) or 2) passed in through the constructor (good)</description>
		<content:encoded><![CDATA[<p>@David,</p>
<p>I am not proposing to have more instances or consume memory. Whether you write you application with Global state (Singleton) or with dependency injection (where you have single instance of a class). You have the same number of objects and hence the same memory consumption. The question at the table is not how many instances of objects you have as that is fixed by the application design, but how do these objects get to where they need to be: 1) Global state (bad) or 2) passed in through the constructor (good)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2991</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Thu, 28 Jan 2010 17:47:09 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2991</guid>
		<description>@Jobob,

this is a very strange question, since the performance of application has nothing to do wether you have a singleton or not. In both case you have same number of objects, the question is not how many objects you have or what is the performance, but how do the references of the objects get to where they need to be. A) Global state, B) passed in through constructor.</description>
		<content:encoded><![CDATA[<p>@Jobob,</p>
<p>this is a very strange question, since the performance of application has nothing to do wether you have a singleton or not. In both case you have same number of objects, the question is not how many objects you have or what is the performance, but how do the references of the objects get to where they need to be. A) Global state, B) passed in through constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2987</link>
		<dc:creator>David</dc:creator>
		<pubDate>Thu, 28 Jan 2010 05:06:45 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2987</guid>
		<description>In interpreted scripting languages like PHP you quickly find that process can eat through several megabytes of memory if you are not careful with your objects and variables. This has lead many PHP developers down the path of singleton in an effort to save memory. 

So depending on the language singleton might be the best way to increase application speed while making testing more difficult. (I&#039;m thinking of a logging or caching class here).

However, it is also a waste of memory to keep objects in memory when they are not needed - which is what a singleton does and, as you state, it also make the code much more spooky than it needs to be.

So I can&#039;t quite give up the idea of all losing all singletons (in PHP) but they defiantly shouldn&#039;t be the norm.</description>
		<content:encoded><![CDATA[<p>In interpreted scripting languages like PHP you quickly find that process can eat through several megabytes of memory if you are not careful with your objects and variables. This has lead many PHP developers down the path of singleton in an effort to save memory. </p>
<p>So depending on the language singleton might be the best way to increase application speed while making testing more difficult. (I&#8217;m thinking of a logging or caching class here).</p>
<p>However, it is also a waste of memory to keep objects in memory when they are not needed &#8211; which is what a singleton does and, as you state, it also make the code much more spooky than it needs to be.</p>
<p>So I can&#8217;t quite give up the idea of all losing all singletons (in PHP) but they defiantly shouldn&#8217;t be the norm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jobob</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2985</link>
		<dc:creator>jobob</dc:creator>
		<pubDate>Thu, 28 Jan 2010 01:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2985</guid>
		<description>have you done any benchmarks against a singleton based application and a test based application?</description>
		<content:encoded><![CDATA[<p>have you done any benchmarks against a singleton based application and a test based application?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Einführung in TDD &#38; Clean Code Talks &#124; geekcloud.org</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2431</link>
		<dc:creator>Einführung in TDD &#38; Clean Code Talks &#124; geekcloud.org</dc:creator>
		<pubDate>Sun, 22 Nov 2009 15:25:02 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2431</guid>
		<description>[...] Flaw #3: Brittle Global State &amp; Singletons [...]</description>
		<content:encoded><![CDATA[<p>[...] Flaw #3: Brittle Global State &amp; Singletons [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: All About Google &#187; How to think about OO</title>
		<link>http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/comment-page-1/#comment-2022</link>
		<dc:creator>All About Google &#187; How to think about OO</dc:creator>
		<pubDate>Tue, 06 Oct 2009 06:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?page_id=328#comment-2022</guid>
		<description>[...] in OO world. I can already hear the screams, so let me explain why, but first we need to agree that global variables and state is evil. If you agree with previous statement than for a static method to do something interesting it needs [...]</description>
		<content:encoded><![CDATA[<p>[...] in OO world. I can already hear the screams, so let me explain why, but first we need to agree that global variables and state is evil. If you agree with previous statement than for a static method to do something interesting it needs [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

