<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx</link><description>Eric recently posted a blog: &amp;#8220; Property or backing store from inside a class? &amp;#8221;, and I responded in a way that skirted the issue entirely. I want to discuss them in a little more detail. Part 1: Why bother? First, why do we use properties?</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123420</link><pubDate>Thu, 29 Apr 2004 23:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123420</guid><dc:creator>milbertus</dc:creator><description>I've been thinking that public fields are the way to go over properties. My only problem with the readonly approach is that it makes the field readonly for code both outside and within the class. While I know there are cases where you can initialize a variable once and never change its value again, there are also times when members of the class need to change the value, while code outside of the class shouldn't be allowed to. Sadly, the readonly approach doesn't work in this case.</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123434</link><pubDate>Fri, 30 Apr 2004 00:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123434</guid><dc:creator>jaybaz [MS]</dc:creator><description>When you find yourself considering a property, try asking if there's a refactoring to be done.  See if putting the field + property behavior into a new class could make sense.  &lt;br&gt;&lt;br&gt;Properties aren't useless; there are times when they're exactly what you want.  But I think they're overused today, to the detriment of code clarity.</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123438</link><pubDate>Fri, 30 Apr 2004 00:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123438</guid><dc:creator>Sean Terry</dc:creator><description>Food for thought, certainly.  However, public fields don't fit the bill for my needs.  Data validation and security checks are common things I use in my properties.</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123439</link><pubDate>Fri, 30 Apr 2004 00:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123439</guid><dc:creator>jaybaz [MS]</dc:creator><description>Sean: In your situation, does creating a class to handle the validation and security make sense?  Does it make cleaner, more OO code?&lt;br&gt;&lt;br&gt;(At this stage in my live, I'm in the more OO=better.  I'm sure I'll swing back sometime.)</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123455</link><pubDate>Fri, 30 Apr 2004 00:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123455</guid><dc:creator>Paul Wilson</dc:creator><description>Binding expects properties, not fields.</description></item><item><title>Generic Lazy Load Object</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123515</link><pubDate>Fri, 30 Apr 2004 05:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123515</guid><dc:creator>Wizzy's World</dc:creator><description /></item><item><title>Generic Lazy Load Class</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123518</link><pubDate>Fri, 30 Apr 2004 05:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123518</guid><dc:creator>Wizzy's World</dc:creator><description /></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123519</link><pubDate>Fri, 30 Apr 2004 02:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123519</guid><dc:creator>Scott Wisniewski</dc:creator><description>I posted a lazy load class on my blog.&lt;br&gt;I'm still downloading the technology preview so I haven't checked the syntax yet, but it communicates the overall idea, and it should work. </description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123527</link><pubDate>Fri, 30 Apr 2004 02:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123527</guid><dc:creator>Scott Wisniewski</dc:creator><description>The WYSYG editor ended up interpreting all my &amp;quot;&amp;lt;T&amp;gt;&amp;quot;'s at tags. I had to switch to html view and then change escape out the &amp;quot;&amp;lt;&amp;quot; and the &amp;quot;&amp;gt;&amp;quot; and the corrected the problem. You should be able to view the correct code now.</description></item><item><title>Jay and Properties...</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123589</link><pubDate>Fri, 30 Apr 2004 07:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123589</guid><dc:creator>Eric Gunnerson's C# Compendium</dc:creator><description /></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123751</link><pubDate>Fri, 30 Apr 2004 12:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123751</guid><dc:creator>Chris J. Breisch</dc:creator><description>Well, I can't say that I haven't thought of this myself.  However, I think I'll keep on using properties.  Why?  Because I like to be able to do foo.Property = value;&lt;br&gt;&lt;br&gt;And I like to be able to check for valid assignments in my setters.  I suppose I could do it without a setter and use a method, but that doesn't seem as 'clean' to me.&lt;br&gt;&lt;br&gt;Perhaps it's becuase I write a lot of class libraries and you seem not to that I look at things this way.&lt;br&gt;&lt;br&gt;Also, setting your public fields to readonly seems very short-sighted to me.  And I'm not talking necessarily about Future-Proofing my code.  But in very few classes to I have a property/field value that can be set once and is never changed by anything again.  Public field seems fine for that extremely rare occurrence, since you don't need to worry about any logic for setting/retrieving.  &lt;br&gt;&lt;br&gt;Now, if I'm using TDD, I might be able to create a field as public readonly in an early step, but it's almost certain to change as I move on.  I suppose I could always start with that, but I know I don't want a public writable field, so as soon as I determine that it's writable (which is most of the time) then I'd have to change that.  Seems pointless to have to always keep doing the same refactoring.  I'd much rather go ahead and make them be properties, and then if I determine later that that's not necessary, I can refactor back to a public readonly field.  Seems like this would be necessary much less often.</description></item><item><title>More on public properties</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123819</link><pubDate>Fri, 30 Apr 2004 16:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123819</guid><dc:creator>Mikel Berger</dc:creator><description>More info properties. This sort of extends on the topic Kyle covered in his article. In Jay's post the read only situation was something I hadn't thought of with sticking with the simpler public properties. But really, regardless of which method you use if you decide to go from a read/write to a read only you're going to break something. Jay wrote a post entitled Properties? Not my bag, baby. When I first started writing C# code, I used properties for everything. But recently, I've felt that I was wasting a lot of time writing trivial properties. Yes, I know that in Whidbey I'll be able to use expansions to write them easily, but that still means that I have to deal with the property bodies cluttering up my code. So, that got me thinking about whether it makes sense to be writing properties in the first place. After a bit of thought, here's my current position: Properties are&amp;amp;nbsp;a great thing for component libraries. There are certainly cases where you would want the future-proofing and decoupling that properties gives you. But when you're working on a single project that gets built all at once, I don't think you're getting any future-proofing benefits, and you have to pay the &amp;amp;#8220;property tax&amp;amp;#8221; the whole time. This may be heretical, since &amp;amp;#8220;use properties&amp;amp;#8221; has been the common guideline. What do you think? [C# Stuff]...</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123863</link><pubDate>Fri, 30 Apr 2004 14:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123863</guid><dc:creator>Ryan Farley</dc:creator><description>Paul mentioned this, but there are things to consider when deciding to use properties vs. public fields (as Jay also mentioned in the post). For example, if you choose to use public fields instead of properties then you better make sure that you'd never want to bind the object since you won't be able to unless you use properties. </description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#123986</link><pubDate>Fri, 30 Apr 2004 17:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:123986</guid><dc:creator>Sean</dc:creator><description>What about performance/GC concerns?&lt;br&gt;&lt;br&gt;This isn't my area, but this question actually just came up..&lt;br&gt;&lt;br&gt;Will value = foo.publicField make the lifetime of foo dependent on value ifn foo falls out of scope (and value doesn't)?&lt;br&gt;&lt;br&gt;versus&lt;br&gt;&lt;br&gt;value = foo.Property.. &lt;br&gt;&lt;br&gt;&lt;br&gt;Using public fields seems alot like a Mort line of thinking.. but if you're in a Mort factory, why not ;)&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#124130</link><pubDate>Fri, 30 Apr 2004 20:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:124130</guid><dc:creator>Shawn</dc:creator><description>jaybaz said: &amp;quot;Wait, doesn’t that open a risk that someone might set the value, when they shouldn’t?  Yeah, but it doesn’t scare me much.  I rarely find myself writing code that manipulates the values in other objects.  It’s bad behavior on my part, and rarely necessary.  If it does happen, and it’s a problem later, I will fix it then.&amp;quot;&lt;br&gt;&lt;br&gt;&lt;br&gt;In my book, that's a potential problem.  Its better to code defensively than to take the attitude of &amp;quot;I'll fix it later&amp;quot;.  I rarely expose a public field because more often than not, I end up needing to use properties for various reasons (granted, I usually write libraries and frameworks so perhaps we are in a different boat).&lt;br&gt;&lt;br&gt;I tend to think more futuristically and if I can foresee a potential expansion of its use, I'll code appropriately.  What do I do in those cases where I write all these properties and all they will ever do is wrap a variable that may just as well have been a public field?  I write the property anyway.  I personally, prefer to use properties anyway.  However, I do often expose readonly properties and they have their use there, as well.&lt;br&gt;&lt;br&gt;I typically use the properties internally as much as I would externally.  There are only a few instances where I operate directly on the field.  Especially if my class might be inheritied, all the more I use the properties rather than the private members (unless there is a good reason and sometimes there is, but it is the exception rather than the rule).&lt;br&gt;&lt;br&gt;Thanks,&lt;br&gt;Shawn</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#125377</link><pubDate>Tue, 04 May 2004 01:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:125377</guid><dc:creator>jaybaz [MS]</dc:creator><description>Chris says &amp;quot;I write a lot of class libraries and you seem not to that I look at things this way&amp;quot;.  &lt;br&gt;&lt;br&gt;My stated approach is that I'm always writing class libraries.  Even when my final goal is an application, I want to create it by first creating the ideal class library for my application, and then having a very small Main() method.&lt;br&gt;&lt;br&gt;If I want to have verification in my setter, of course I won't use a public field.  &lt;br&gt;&lt;br&gt;But as long as I know I can rebuild all the consumers of the code I write, then I will only create a new property if it actually improves the clarity of my code.</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#127412</link><pubDate>Thu, 06 May 2004 20:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:127412</guid><dc:creator>Remas Wojciechowski</dc:creator><description>Just a couple of thoughts why I think it's a good idea to actually use properties (mostly relates to ASP.NET):&lt;br&gt;&lt;br&gt;1. DataGrid-enabled Business Objects for ASP.NET&lt;br&gt;While working with data, I like to encapsulate data from DBs into strongly-typed objects. If I use fields in my class, the (asp:)DataGrid object won't be able to render the properties when AutoGenerateColumns=true.&lt;br&gt;&lt;br&gt;2. Caching&lt;br&gt;When data is expensive to get, you want to cache it. Say you use an Application variable to that end. Since business objects are likely to be used by more than one control, it's not very comfy to access the Application property directly (null? typos, etc.). My favorite approach is to encapsulate it into a property. Only with a property can you fill the cache if it's empty without the user of that class having to take care of it.&lt;br&gt;&lt;br&gt;BTW, you can declare a property in one line ;-) C makes it possible</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#127433</link><pubDate>Thu, 06 May 2004 20:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:127433</guid><dc:creator>jaybaz [MS]</dc:creator><description>Maybe I'm being picky, but I think that caching isn't the goal, it's lazy creation.  &lt;br&gt;&lt;br&gt;Here's a lazy loader that encapsulate those semantics in a nice, OO way: &lt;a target="_new" href="http://blogs.msdn.com/jaybaz_ms/archive/2004/04/30/124229.aspx"&gt;http://blogs.msdn.com/jaybaz_ms/archive/2004/04/30/124229.aspx&lt;/a&gt;&lt;br&gt;</description></item><item><title>A pointer to a insightful criticisim of C# Properties</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#127969</link><pubDate>Fri, 07 May 2004 16:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:127969</guid><dc:creator>Julien Couvreur (Dumky)</dc:creator><description>&lt;a target="_new" href="http://www.geocities.com/csharpfaq/properties.html"&gt;http://www.geocities.com/csharpfaq/properties.html&lt;/a&gt;</description></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#128178</link><pubDate>Fri, 07 May 2004 22:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:128178</guid><dc:creator>jaybaz [MS]</dc:creator><description>Hmm, I think the article you pointed to is a bit inflamatory.  For example, the reasons stated to never use structs are mitigated if you only use immutable structs.</description></item><item><title>Properties as objects</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#155455</link><pubDate>Tue, 15 Jun 2004 00:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:155455</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>re: Properties?  Not my bag, baby.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#156609</link><pubDate>Tue, 15 Jun 2004 23:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156609</guid><dc:creator>Sean Malloy</dc:creator><description>I've been using fields as properties since day one.&lt;br&gt;&lt;br&gt;In an in-house project, where your team controls all the code, its easy to do.&lt;br&gt;&lt;br&gt;You can upgrade a field to a property late ron, if you need additional code wrapped around the get/set later on.&lt;br&gt;&lt;br&gt;Java can not do it. You eithe rhave the choice of public fields, or get/set methods, which means modifying all consumer code - PITA.&lt;br&gt;&lt;br&gt;C# allows you to upgrade fields on a case-by-case basis. As jaybaz points out, a public readonly field is effectively the same as a get property (Except you have to init the field at construction time...)&lt;br&gt;&lt;br&gt;Its just a nice path.. all public fields, save code.. upgrade necessary fields to properties as required... repeat.</description></item><item><title>Properties?  One of the best enhancements to OOP!</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#181530</link><pubDate>Tue, 13 Jul 2004 07:35:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:181530</guid><dc:creator>Mike Schinkel</dc:creator><description>Funny, my feeling has always been that properties were one of the best things added to OOP since its early days.&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt; It takes a simple idea (a field in a class) and makes it take 6 lines.  This clutters my code. &lt;br&gt;&lt;br&gt;That's because C# was not implemented to streamline the definition of properties. If it was, this wouldn't be an issue.  So I say don't confuse concept with implementation.&lt;br&gt;&lt;br&gt;However, I think one of the biggest problems is that Microsoft chose to implement fields as having different signatures than properties (ugh!)  If you could define a field and later change to a property w/o affecting clients, there would be no need to define a property prematurely and use 6 lines of code when one would do.&lt;br&gt;&lt;br&gt;So, I think the designers of C# (and VB) caused this problem.  And please don't say that fields are different than properties for performance reasons because most of the time that doesn't matter, and MS could have defined fields has having something like a &amp;quot;direct&amp;quot; qualifier that would cause them to behave like fields behave today when you someone really needs them to be super fast (but doing so would limit future compatibility w/properties.)&lt;br&gt;</description></item><item><title>Thoughts on bit fields.</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#350724</link><pubDate>Tue, 11 Jan 2005 20:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:350724</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description /></item><item><title>Reflection and the ObjectDataSource Control for ASP.NET 2.0</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#358737</link><pubDate>Sat, 22 Jan 2005 23:56:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:358737</guid><dc:creator>TheChaseMan's Frenetic SoapBox</dc:creator><description /></item><item><title>Reflection and the ObjectDataSource Control for ASP.NET 2.0</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#358739</link><pubDate>Sat, 22 Jan 2005 23:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:358739</guid><dc:creator>TheChaseMan's Frenetic SoapBox</dc:creator><description /></item><item><title>properties vs. fields... again</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#1629886</link><pubDate>Fri, 09 Feb 2007 00:29:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1629886</guid><dc:creator>jaybaz [MS] WebLog</dc:creator><description>&lt;p&gt;Eric Gunnerson just posted Properties vs public fields redux... It's no secret that I agree with Eric&lt;/p&gt;
</description></item><item><title>Movies &amp;raquo; jaybaz [MS] WebLog</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#6944929</link><pubDate>Wed, 02 Jan 2008 03:33:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6944929</guid><dc:creator>Movies » jaybaz [MS] WebLog</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://movies.247blogging.info/?p=4445"&gt;http://movies.247blogging.info/?p=4445&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> jaybaz MS WebLog Properties Not my bag baby | Insomnia Cure</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#9710573</link><pubDate>Tue, 09 Jun 2009 01:38:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9710573</guid><dc:creator> jaybaz MS WebLog Properties Not my bag baby | Insomnia Cure</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://insomniacuresite.info/story.php?id=1090"&gt;http://insomniacuresite.info/story.php?id=1090&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> jaybaz MS WebLog Properties Not my bag baby | porch swing</title><link>http://blogs.msdn.com/jaybaz_ms/archive/2004/04/29/123333.aspx#9782081</link><pubDate>Fri, 19 Jun 2009 10:39:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9782081</guid><dc:creator> jaybaz MS WebLog Properties Not my bag baby | porch swing</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://fancyporchswing.info/story.php?id=177"&gt;http://fancyporchswing.info/story.php?id=177&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>