Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
GeneralRe: Mike Hankey PinmemberMike Hankey21-May-14 7:17 
GeneralRe: Mike Hankey PinmemberJimmyRopes21-May-14 4:49 
GeneralIs this HttpListener BUG? Pinmembersenlin11020-May-14 18:38 
GeneralRe: Is this HttpListener BUG? Pinprofessional_Damian S_20-May-14 18:45 
GeneralRe: Is this HttpListener BUG? PinprotectorOriginalGriff20-May-14 19:59 
GeneralRe: Is this HttpListener BUG? PinprofessionalSuvabrata Roy20-May-14 21:25 
GeneralRe: Is this HttpListener BUG? PinprofessionalEddy Vluggen21-May-14 8:06 
GeneralProperty or a method. This seems wrong. PinadminChris Maunder20-May-14 17:46 
I read the article from the Insider[^] about properties and methods and the author states
 
Issue 1.
 
Quote:
Properties should be stable: that is, the value of a property shouldn't change “on its own". Rather, changes in properties are the results of calling property setters, or some other action changing the state of the object

So the mass of a car can be a property since it doesn't change, but the total mass, including fuel, can't be since fuel is burned and so changes.
 
A specific example is DateIime.Now which should not be a property because it changes and really ought to have been a method GetCurrentDateIime.
 
I'm assuming the author means we should have a IimeZone object with a Now property, with Now being updated explicitly through some process such as TimeZone.Now = DateTime.GetCurrentDateIime(). Which seems a great way to spend your spare CPU cycles.
 
Can someone smarter than me please explain why properties should only be things that can't change? To stretch the car analogy if you have an Engine and Radiator object with the Radiator having a property Temperature then I can accept the argument that the water doesn't get hotter on its own. You'd have something like
 
class Engine
{
    void RunEngine()
    {
        ...
        water.Temperature += Degrees(10);
        ...
    }
}
 
But what of the Car object that aggregates an Engine and a Radiator object? The car's EngineIemperature property (which is a façade for the Engine.Temperature property) is going to change "on its own" sorta kinda. It'll change due to changes passed on by internal objects.
 
Issue 2.
 
The author states
Quote:
Property getters should always succeed: they should never throw an exception. Return some reasonable default value if the property cannot be logically computed right now because the object is in a bad state.

Doesn't this fly in the face of the "use exceptions not error codes" argument. I understand we're not talking about returning an error code - we're talking about completely hiding the fact that there was an error and simply returning a value that is "reasonable". In fact aren't we simply bypassing the entire exception-vs-errorcode debate and simply ignore it?
 
Sure - you can return null values for properties that don't currently exist on an object, but what if a property is expansive to retrieve and a timeout / resource error / whatever happens while querying the property. Surely something should be mentioned to the caller that may the value they have is a little dodgy and maybe they should try again later?
 

All in all this seems like a discussion on theoretical guidelines that ignore important realities.
 
What are your thoughts? Where am I going wrong in my thinking here?
cheers
Chris Maunder

AnswerRe: Property or a method. This seems wrong. PinmemberSuper Lloyd20-May-14 18:35 
GeneralRe: Property or a method. This seems wrong. PinmemberPIEBALDconsult20-May-14 19:01 
GeneralRe: Property or a method. This seems wrong. PinmemberJim Meadors20-May-14 19:20 
GeneralRe: Property or a method. This seems wrong. Pinprofessional_Maxxx_20-May-14 19:40 
GeneralRe: Property or a method. This seems wrong. PinadminChris Maunder21-May-14 4:10 
GeneralRe: Property or a method. This seems wrong. PinprofessionalRage21-May-14 5:58 
GeneralRe: Property or a method. This seems wrong. PinmemberDavid O'Neil20-May-14 19:56 
GeneralRe: Property or a method. This seems wrong. PinmvpCPallini20-May-14 20:09 
GeneralRe: Property or a method. This seems wrong. [modified] PinmemberBillWoodruff20-May-14 20:09 
GeneralRe: Property or a method. This seems wrong. PinprofessionalJeremy Falcon21-May-14 4:03 
GeneralRe: Property or a method. This seems wrong. PinadminChris Maunder21-May-14 4:11 
GeneralRe: Property or a method. This seems wrong. Pinmemberpwasser20-May-14 20:13 
GeneralRe: Property or a method. This seems wrong. PinprofessionalJörgen Andersson20-May-14 20:22 
GeneralRe: Property or a method. This seems wrong. PinadminChris Maunder21-May-14 4:13 
GeneralRe: Property or a method. This seems wrong. PinprofessionalJörgen Andersson21-May-14 4:41 
GeneralRe: Property or a method. This seems wrong. PinprofessionalV.20-May-14 21:11 
GeneralRe: Property or a method. This seems wrong. PinmemberGary Wheeler21-May-14 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 25 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid