Boolean flags naming


Link to this posting

Postby Ursego » 21 Feb 2013, 21:32

Don't give Boolean variables and parameters "super-universal" names like flag, mode or switchIt. Instead, write what exactly they flag/switch, or which mode set.

For example, if a method's argument enables or disables fields with personal information then call it enablePersonalInfo - you should describe what the argument is doing or which information it brings, you don't need to explain other programmers what Boolean type is! :lol: The only exception to this rule - if the meaning of the Boolean argument is conveyed by the method's name: for example, the method setReadOnlyMode() can have an argument named simply switchIt (so it's understood that passing false cancels the mode), even though I would name that argument readOnlyMode.
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker