Naming of boolean column in database table [closed]
Want to improve this question? Update the question so it can be开发者_如何学JAVA answered with facts and citations by editing this post.
Closed last month.
The community reviewed whether to reopen this question last month and left it closed:
Improve this questionOriginal close reason(s) were not resolved
I have 'Service' table and the following column description as below
- Is User Verification Required for service ?
- Is User's Email Activation Required for the service ?
- Is User's Mobile Activation required for the service ?
I Hesitate in naming these columns as below
IsVerificationRequired
IsEmailActivationRequired
IsMobileActivationRequired
or
RequireVerification
RequireEmailActivation
RequireMobileActivation
I can't determined which way is the best .So, Is one of the above suggested name is the best or is there other better ones ?
I would (and do) use "IsVerificationRequired"
I try to add some meaning to my column names so it's obvious (ValueDate, InsertedDateTime, IsActive, HazCheezBurger, ProductName etc). "Isxxxx" implies yes/no for example without thinking and you only have 2 states unlike "ProductName".
Run with the Is
variants, or at the very least swap the Require
to Requires
. Booleans should be phrased as questions. Is, Can, Has, Should, they're all good prefixes for Boolean functions/columns. See 1370840 for more arguments on this
I would choose VerificationRequired, EmailActivationRequired etc.
Database is the snapshot of the state, so the above said column names goes better over the ones you have mentioned in my opinion.
I would go for the one that fits more the syntax you are using in your current project. Either one is fine since they describe what the variable contains, the only thing you need to worry about is that you keep the same naming standard for all your project. If you haven't decide any naming standard for your project yet, the first one would be better since it is what is closer of the Java Bean naming standard which is something that a lot of developer are used to.
Neither. Name the column such that it makes sense if "is" were to be prepended, but don't prepend it:
VerificationRequired
EmailActivationRequired
MobileActivationRequired
The datatype being boolean
implies the "is" - you don't need to load it into the variable/field name. Just as you shouldn't name timestamp columns with "timestamp", eg define the column as expiry timestamp
not expiry_timestamp timestamp
.
Adding is
to the name is a form of Hungarian notation, which has long been accepted as an anti-pattern.
In java, the convention is to name of the accessor method of a field (especially on a DTO) as isX
rather than the usual getX
because it reads more naturally, eg:
public boolean isVerificationRequired { return verificationRequired; }`
reads more naturally than:
public boolean getVerificationRequired { return verificationRequired; }`
Or name the accessor hasX
if it reads more naturally.
Whether you name the accessor isX
or hasX
, a boolean
field (in your case a database column) should not have is
or has
in its name.
精彩评论