<?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: Coding: Setters reduce trust</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17: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: Good Lazy and Bad Lazy at Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-20377</link>
		<dc:creator>Good Lazy and Bad Lazy at Mark Needham</dc:creator>
		<pubDate>Tue, 21 Jul 2009 13:12:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-20377</guid>
		<description>[...] Adding setters to a class when we have some extra data that we want to put inside that class instead of taking the time to either change the constructor to take in the new data or considering if we now need to create a new class to better represent the system. The problem here is that we end up with objects that may be half initialised which makes them really difficult to work with later on. [...]</description>
		<content:encoded><![CDATA[<p>[...] Adding setters to a class when we have some extra data that we want to put inside that class instead of taking the time to either change the constructor to take in the new data or considering if we now need to create a new class to better represent the system. The problem here is that we end up with objects that may be half initialised which makes them really difficult to work with later on. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gil Zilberfeld</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-17600</link>
		<dc:creator>Gil Zilberfeld</dc:creator>
		<pubDate>Mon, 25 May 2009 05:36:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-17600</guid>
		<description>It&#039;s an interesting point of view. I can definitely see the why you would use immutable objects, when needed. 
I do have an aversion for big constructors (with many params) as the code is less readable, and therefore lowering the maintainability of the code - the same thing we&#039;re trying to avoid by making objects immutable.

I do agree with a better IDE suggestion. Get the best tool you can - they will make your life easier.</description>
		<content:encoded><![CDATA[<p>It&#8217;s an interesting point of view. I can definitely see the why you would use immutable objects, when needed.<br />
I do have an aversion for big constructors (with many params) as the code is less readable, and therefore lowering the maintainability of the code &#8211; the same thing we&#8217;re trying to avoid by making objects immutable.</p>
<p>I do agree with a better IDE suggestion. Get the best tool you can &#8211; they will make your life easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SCdF</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-17582</link>
		<dc:creator>SCdF</dc:creator>
		<pubDate>Mon, 25 May 2009 00:09:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-17582</guid>
		<description>You&#039;re right in theory.

However, I have come across situations where being able to &#039;partially&#039; initilise objects comes in handy, mostly when it means you can create a reference to the object before all the data it requires is available.

I once had to deal with a data structure that someone had written that was similar to a graph. Defining a node that points to another node that points back to that node was impossible without modifying the code to provide setters.

Granted, this is due to the arguably bad design of the data structure, but I do think there are legitimate uses for this.

As an aside, wrt the &quot;it turns refactoring from a single change to a constructor argument to a line-by-line search for property assignments&quot; comment-- get a better IDE ;-).</description>
		<content:encoded><![CDATA[<p>You&#8217;re right in theory.</p>
<p>However, I have come across situations where being able to &#8216;partially&#8217; initilise objects comes in handy, mostly when it means you can create a reference to the object before all the data it requires is available.</p>
<p>I once had to deal with a data structure that someone had written that was similar to a graph. Defining a node that points to another node that points back to that node was impossible without modifying the code to provide setters.</p>
<p>Granted, this is due to the arguably bad design of the data structure, but I do think there are legitimate uses for this.</p>
<p>As an aside, wrt the &#8220;it turns refactoring from a single change to a constructor argument to a line-by-line search for property assignments&#8221; comment&#8211; get a better IDE <img src='http://www.markhneedham.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morten Lyhr</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-17564</link>
		<dc:creator>Morten Lyhr</dc:creator>
		<pubDate>Sun, 24 May 2009 19:23:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-17564</guid>
		<description>Actually a setter on a real object, that pretty much always breaks encapsulation.

On the other hand if it is data object(some call it DTO), there is no reason not to have properties with setters.

I tend to have properties in pure data objects with no logic and no properties in my real objects. The real objects can depend on a data objects, just like it can depend on a simple type like strins, ints etc. Data objects can also be returned from real objects like the result of a calculation.</description>
		<content:encoded><![CDATA[<p>Actually a setter on a real object, that pretty much always breaks encapsulation.</p>
<p>On the other hand if it is data object(some call it DTO), there is no reason not to have properties with setters.</p>
<p>I tend to have properties in pure data objects with no logic and no properties in my real objects. The real objects can depend on a data objects, just like it can depend on a simple type like strins, ints etc. Data objects can also be returned from real objects like the result of a calculation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Riley</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-17503</link>
		<dc:creator>Ryan Riley</dc:creator>
		<pubDate>Sat, 23 May 2009 17:38:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-17503</guid>
		<description>Well said. I&#039;m very hesitant to just rely on setters. In general, I try not to use setters whatsoever. After learning a bit about the benefits of immutability, I really have a hard time allowing things to change after they are set. I find myself using the Builder pattern to store up what I want and then passing those parameters into a constructor or loading a DTO to load my domain models. No setters necessary.

@Tim, I don&#039;t think you can just discount null reference checks as setter issues. I&#039;ve seen numerous cases where nulls are passed into the constructors and caused the same issues.</description>
		<content:encoded><![CDATA[<p>Well said. I&#8217;m very hesitant to just rely on setters. In general, I try not to use setters whatsoever. After learning a bit about the benefits of immutability, I really have a hard time allowing things to change after they are set. I find myself using the Builder pattern to store up what I want and then passing those parameters into a constructor or loading a DTO to load my domain models. No setters necessary.</p>
<p>@Tim, I don&#8217;t think you can just discount null reference checks as setter issues. I&#8217;ve seen numerous cases where nulls are passed into the constructors and caused the same issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Robinson</title>
		<link>http://www.markhneedham.com/blog/2009/05/23/coding-setters-reduce-trust/comment-page-1/#comment-17483</link>
		<dc:creator>Tim Robinson</dc:creator>
		<pubDate>Sat, 23 May 2009 08:47:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1235#comment-17483</guid>
		<description>You&#039;re right that having extra initialization to do after constructing an object reduces trust in that class -- I hate coming across code full of null reference checks (on properties that can never be null) because somebody got bitten by an exception once.

The other thing you lose with setter properties, compared to constructor arguments, is the ability to track where data comes from and when.

Because a property is writable, you can never be sure that some other piece of code overwrites your value later on: it turns refactoring from a single change to a constructor argument to a line-by-line search for property assignments.</description>
		<content:encoded><![CDATA[<p>You&#8217;re right that having extra initialization to do after constructing an object reduces trust in that class &#8212; I hate coming across code full of null reference checks (on properties that can never be null) because somebody got bitten by an exception once.</p>
<p>The other thing you lose with setter properties, compared to constructor arguments, is the ability to track where data comes from and when.</p>
<p>Because a property is writable, you can never be sure that some other piece of code overwrites your value later on: it turns refactoring from a single change to a constructor argument to a line-by-line search for property assignments.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

