[wx-dev] what should IsEnabled() really return?

Aggro aggro at pp.inet.fi
Fri Mar 16 16:11:41 PDT 2007


Vadim Zeitlin wrote:

>  Stefan wants this IsLatentlyEnabled(). I prefer IsThisEnabled(). Any other
> versions or votes for the best name?
> 
>  Anyhow, if there are no objections to this very soon, I'm going to check
> in a patch changing IsEnabled() return value and adding this new
> IsMysteriousNameEnabled().

The problem is that people could easily just find the IsEnabled() and 
miss the IsMysteriousNameEnabled() and use the IsEnabled() happily, 
trusting that it will return false when the object itself or it's parent 
is disabled.

To avoid this confusion, we could just add a parameter for the 
IsEnabled(), which could be a boolean value identifying what the user 
really wants. IMHO it should have a default value and by default it 
should return the inherited status.

So basicly a single function would by default return what users by 
default expect it to return and it could also be used for testing, 
without the need of adding extra complexity by inventing weirdly named 
new functions. (Because basicly the suggested two functions are 
returning the same thing.)

So something like this (in pseudo code):

bool IsEnabled( bool returnInheritedValue = true )
{
   if( m_enabled == false )
     return false;

   if( returnInheritedValue && parent.m_enabled == false )
     return false;

   return true;
}




More information about the wx-dev mailing list