75

I have 'Service' table and the following column description as below

  1. Is User Verification Required for service ?
  2. Is User's Email Activation Required for the service ?
  3. 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 ?

Amr Badawy
  • 7,453
  • 12
  • 49
  • 84
  • 1
    I think it is worth mentioning that column names like `IsOwner` do not seem to have a clear alternative. – Alexey May 11 '18 at 07:42

5 Answers5

72

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".

gbn
  • 422,506
  • 82
  • 585
  • 676
  • 4
    A problem comes when generating getters and setters. Most IDE's add `is` to the boolean getters. As an example, if the boolean variable is `verificatedRequired`, getter will be generated as `isVerificationRequired` instead of `getVerificatedRequried`. If you use the variable as `isVerificationRequired` then the getter will be `isIsVerificationRequired`. – Ramesh-X Jul 19 '21 at 12:53
  • 1
    Disagree with this answer. In java, the convention is to name of the accessor method of the DTO corresponding to the DB column X as `isX` rather than the usual `getX`. The *datatype* implies the "is" - you don't need to load it into the variable. Just as you shouldn't name timestamp columns with "timestamp", eg `expiry timestamp` not `expiry_timestamp timestamp`.. Using `is` in the name is a form of hungarian notation, which has long been accepted as an anti-pattern. – Bohemian Nov 19 '22 at 22:20
29

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

Community
  • 1
  • 1
Dan F
  • 11,958
  • 3
  • 48
  • 72
  • 2
    That's an interesting question to reference because it's more about the convention for naming getter methods, not variables. I don't know about other languages but in Java, the convention I've always seen is using the "is" prefix for the getter but NOT the variable. So, for a database, are you considering a column name more like a field or a getter? ;) – spaaarky21 Apr 11 '14 at 22:08
12

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.

  • 2
    I agree. The column names in the form of a question seem like overkill. It would be like naming FirstName and LastName columns "WhatIsTheFirstName" and "WhatIsTheLastName". Which is clearly silly. – MJB Jun 14 '10 at 12:41
  • 2
    but i think in some case such this that need either true or false question is so readable that determine true or false not any other value – Amr Badawy Jun 14 '10 at 12:48
  • 2
    @MJB: Not silly. You could also have DateVerificationRequired ! I often replace Boolean fields by date fields if that adds extra information (and of course if the value is subject to change). In that case a Null indicates the condition is not met (yet). – iDevlop Jun 14 '10 at 12:55
3

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.

HoLyVieR
  • 10,985
  • 5
  • 42
  • 67
1

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.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • I don't agree with this. `VerificationRequired` doesn't tell the whole story. That could mean "was Verification required" or "will Verification be required" or "what date was/will Verification be required" or even "what type of Verification is required". I don't think `IsVerificationRequired` really falls into Hungarian notation. I would say rather that it is descriptive naming a-la Clean Code. You could say that the data type gives the missing information but I can immediately understand `IsVerificationRequired` when reading code. – Caltor Jan 18 '23 at 11:20
  • 1
    @Caltor `VerificationRequired` always means "is", not "was"; databases store the state of something, so everything is the current data. If it were to mean "was", your data needs updating. Users of the data rely on "is" semantic. – Bohemian Jan 18 '23 at 17:02
  • We are quite literally arguing over semantics here but I disagree with this too. Databases store data. Whether or not that is current state is down to the designer. Database records could be historical transactions or future bookings for example. VerificationRequired could mean that the person looked under-age to buy alcohol so Verification WAS Required. Or it could mean this person has only limited ID to board a flight so Verification IS / WILL BE Required. It doesn't help that `Required` in English can be an adjective or the past participle form of the verb `to require`. – Caltor Jan 19 '23 at 13:10
  • Yeah, the Java example only proves that it's correct to use isX. Java was like, "Nah, these bozos are creating ambiguous fields and front end can't make sense of it. Let's make it a convention to fix it". Caltor (and Java) are correct, getVerificationRequired could mean anything BUT getIsVerificationRequired ALWAYS means "I'm getting a boolean about 'Is Verification Required' here". – user1567453 Jul 19 '23 at 05:47
  • @user1567453 The convention is not `getIsVerificationRequired()` but rather `isVerificationRequired()` for accessor methods of boolean fields. – Bohemian Jul 19 '23 at 07:43