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– Peter Rowell2018年07月26日 18:49:08 +00:00Commented Jul 26, 2018 at 18:49
-
@PeterRowell I believe OP is asking if the name choice for the variable is the proper oneDarkCygnus– DarkCygnus2018年07月26日 18:53:34 +00:00Commented Jul 26, 2018 at 18:53
-
@DarkCygnus yes, I just want to know how should look like proper variable names, I apologize for the misunderstandingAdam A– Adam A2018年07月26日 18:55:47 +00:00Commented Jul 26, 2018 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– Peter Rowell2018年07月26日 19:02:48 +00:00Commented Jul 26, 2018 at 19:02
3 Answers 3
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;
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.
-
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– Adam A2018年07月26日 19:18:58 +00:00Commented Jul 26, 2018 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.isBeingEditedDarkCygnus– DarkCygnus2018年07月27日 03:16:35 +00:00Commented Jul 27, 2018 at 3:16
-
4I 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– David Arno2018年07月27日 07:06:50 +00:00Commented Jul 27, 2018 at 7:06 -
@DavidArno that would read
myPasswordForm.passwordIsBeingEdited
which IMHO is more redundant (and longer) thanmyPasswordForm.isBeingEdited
DarkCygnus– DarkCygnus2018年08月17日 20:16:38 +00:00Commented Aug 17, 2018 at 20:16 -
@DarkCygnus Your flag denotes that the form is being edited. Is that really what you meant?David Arno– David Arno2018年08月17日 20:30:23 +00:00Commented Aug 17, 2018 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.