Click here to Skip to main content
15,892,809 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Mike Hankey Pin
Mike Hankey21-May-14 7:17
mveMike Hankey21-May-14 7:17 
GeneralRe: Mike Hankey Pin
JimmyRopes21-May-14 4:49
professionalJimmyRopes21-May-14 4:49 
GeneralIs this HttpListener BUG? Pin
senlin11020-May-14 18:38
senlin11020-May-14 18:38 
GeneralRe: Is this HttpListener BUG? Pin
_Damian S_20-May-14 18:45
professional_Damian S_20-May-14 18:45 
GeneralRe: Is this HttpListener BUG? Pin
OriginalGriff20-May-14 19:59
mveOriginalGriff20-May-14 19:59 
GeneralRe: Is this HttpListener BUG? Pin
Suvabrata Roy20-May-14 21:25
professionalSuvabrata Roy20-May-14 21:25 
GeneralRe: Is this HttpListener BUG? Pin
Eddy Vluggen21-May-14 8:06
professionalEddy Vluggen21-May-14 8:06 
GeneralProperty or a method. This seems wrong. Pin
Chris Maunder20-May-14 17:46
cofounderChris 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. Pin
Super Lloyd20-May-14 18:35
Super Lloyd20-May-14 18:35 
GeneralRe: Property or a method. This seems wrong. Pin
PIEBALDconsult20-May-14 19:01
mvePIEBALDconsult20-May-14 19:01 
GeneralRe: Property or a method. This seems wrong. Pin
Jim Meadors20-May-14 19:20
Jim Meadors20-May-14 19:20 
GeneralRe: Property or a method. This seems wrong. Pin
_Maxxx_20-May-14 19:40
professional_Maxxx_20-May-14 19:40 
GeneralRe: Property or a method. This seems wrong. Pin
Chris Maunder21-May-14 4:10
cofounderChris Maunder21-May-14 4:10 
GeneralRe: Property or a method. This seems wrong. Pin
Rage21-May-14 5:58
professionalRage21-May-14 5:58 
GeneralRe: Property or a method. This seems wrong. Pin
David O'Neil20-May-14 19:56
professionalDavid O'Neil20-May-14 19:56 
GeneralRe: Property or a method. This seems wrong. Pin
CPallini20-May-14 20:09
mveCPallini20-May-14 20:09 
GeneralRe: Property or a method. This seems wrong. Pin
BillWoodruff20-May-14 20:09
professionalBillWoodruff20-May-14 20:09 
GeneralRe: Property or a method. This seems wrong. Pin
Jeremy Falcon21-May-14 4:03
professionalJeremy Falcon21-May-14 4:03 
GeneralRe: Property or a method. This seems wrong. Pin
Chris Maunder21-May-14 4:11
cofounderChris Maunder21-May-14 4:11 
GeneralRe: Property or a method. This seems wrong. Pin
User 5924120-May-14 20:13
User 5924120-May-14 20:13 
GeneralRe: Property or a method. This seems wrong. Pin
Jörgen Andersson20-May-14 20:22
professionalJörgen Andersson20-May-14 20:22 
GeneralRe: Property or a method. This seems wrong. Pin
Chris Maunder21-May-14 4:13
cofounderChris Maunder21-May-14 4:13 
GeneralRe: Property or a method. This seems wrong. Pin
Jörgen Andersson21-May-14 4:41
professionalJörgen Andersson21-May-14 4:41 
GeneralRe: Property or a method. This seems wrong. Pin
V.20-May-14 21:11
professionalV.20-May-14 21:11 
GeneralRe: Property or a method. This seems wrong. Pin
Gary Wheeler21-May-14 0:28
Gary Wheeler21-May-14 0:28 

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

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