It is an age old debate… we have some fairly good guidelines, but they certainly leave room for improvement.   Today at a WinFX API review (for some cool stuff that didn’t make it out in the PDC drop) we had the debate again…  Today the APIs look like:

        public DateTime GetDisconnectTime();

        public TimeSpan GetIdleTime();

        public DateTime GetLogonTime();

        public SessionStates GetSessionStates();

        public WindowsIdentity GetUserInformation();

 

My knee jerk is to make these properties…

        public DateTime DisconnectTime {get; }

        public TimeSpan IdleTime {get; }

        public DateTime LogonTime {get; }

        public SessionStates SessionStates {get; }

        public WindowsIdentity UserInformation {get; }

 

 

 the problem… well, the calls *could* be cross machine…. My worry is if they are cross machine making these guys properties will lead people to write inefficient code (and therefore bring down the wrath of Rico)…

 

Pit of Despair:

 

void Button_Click (object sender, EventArgs arg) {

     label.Text = s.UserInformation.Name;

}

//Problem: You get the nice little “(Not Responding)” title until the network call completes

 

Pit of Success:

void Button_Click (object sender, EventArgs arg) {

 

     label.Text = s.GetUserInformation().Name;

}

//Now, that looks like it is doing something that could be expensive.  A good code review might very well catch the fact that this really needs to be done asynchronously.  The API design leads the user in the right direction.

 

 

So, my question for you… Based on this very limited data I have given you, what should we do here?  Go for properties and hope for the best, or error on the safe side and use methods, something else?