I'm creating a variable which should describe that an object is currently in use. Lets say we have a form with a password input, and I want to describe the state when someone is using that input.

Is that variable name correct?:

Boolean editingPassword = false;

I don't have any idea how it should looks like.

  • Your question is somewhat hard to understand, but I think what you're looking for is some type of mutex or locking system. – Peter Rowell Jul 26 '18 at 18:49
  • @PeterRowell I believe OP is asking if the name choice for the variable is the proper one – DarkCygnus Jul 26 '18 at 18:53
  • @DarkCygnus yes, I just want to know how should look like proper variable names, I apologize for the misunderstanding – Adam A Jul 26 '18 at 18:55
  • @DarkCygnus -- Ah. I guess my answer/question then morphs to: what naming convention are you using? My brain was bent by Simonyi back in 1978 at Xerox and I've been speaking Hungarian ever since. ;-) – Peter Rowell Jul 26 '18 at 19:02

I would work not only on the variable name but also on the variable values by using an enumeration:

enum editionStatus { blank, inProgress, filled };

enum editionStatus passwordEditionStatus = inProgress;
| improve this answer | |

Is that variable name correct?

When naming boolean variables, as they represent states (like the editing), I'd suggest you perpend is on the name. That, along with camel case (which seems what you are using) should suffice:

Boolean isEditingPassword = false;

That will make it clearer that it's a state and not other thing, like the editing password text input, or your editing dialog.

| improve this answer | |
  • Thanks for response, but I wonder how to name that variable impersonally, let say that password form is being used by sth and I dont know what is it. Is it correct: isPasswordBeingEdited ? – Adam A Jul 26 '18 at 19:18
  • 2
    @AdamA in that case this variable will most likely be part of your PasswordForm class or similar, where in that case it will read better using just isBeingEdited. When accessing the attribute it will read naturally: myPwdForm.isBeingEdited – DarkCygnus Jul 27 '18 at 3:16
  • 4
    I really dislike this convention as the variable name ends up as grammatic nonsense. It's far better, in my view, to describe what the variable does in plain English (or French, German, or whatever), eg passwordIsBeingEdited. – David Arno Jul 27 '18 at 7:06
  • @DavidArno that would read myPasswordForm.passwordIsBeingEdited which IMHO is more redundant (and longer) than myPasswordForm.isBeingEdited – DarkCygnus Aug 17 '18 at 20:16
  • @DarkCygnus Your flag denotes that the form is being edited. Is that really what you meant? – David Arno Aug 17 '18 at 20:30

If you are going in this direction one would think that it would be a good idea to simply add it to basically every form you have, that being said a name along to lines of isBeingEdited would work nicely, especially in the form of PasswordForm.isBeingEdited. This way the information does not get doubled up and look like PasswordForm.PasswordisBeingEdited or whatever you end up using instead

Another way would also be to represent each field of the form with its own isBeingEdited that way you could have multiple text fields in one form without worry in the form of LoginForm.PasswordField.isBeingEdited and the like.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.