Search code examples
c#.netdesign-guidelines

What is the FDG for naming boolean properties?


What is the Framework Design Guideline for naming boolean properties? If there isn't one, then what's your recommendation?

Let's say I have a User class, and I need a property that specifies if the user is enabled or not. These are the options I can think of:

  • Enable
  • Enabled
  • IsEnabled
  • Disable
  • Disabled
  • IsDisabled

Also, if the BL says that the user must be disabled by default and explicitly enabled, should I prefer an 'enable' variation, considering that the default value for System.Boolean is false ?


Solution

  • The Framework Design Guidelines (Brad Abrahms and Krzysztof Cwalina) say to use either Enabled or IsEnabled (section 3.6.2). They say to use affirmative phrases (ie. CanSeek instead of CantSeek), and to use the most readable version (ie. Created is more readable than IsCreated).

    I would personally use Enabled in your case, with a default value of false. User.Enabled reads well and is clear in what its meaning is.