Question

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.

Was it helpful?

Solution

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;

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
scroll top