views:

122

answers:

7

I have a property that indicates whether the instance could be modified. Should it be named MayModify or CanModify?

+1  A: 

CanModify is better, because can represents ability. But May is more like someone is not against, not that definite.

Andrey
+4  A: 

IsModifiable

CanModify

AllowChanges

MayModify sounds too conditional, sort of grey as opposed to boolean black and white.

I would usually use a verb followed by a noun. Ie:

Allow, then Changes.

CanModify is two verbs/actions which I think is confusing.

awrigley
A: 

CanModify make more sense.

saurabh
+1  A: 

Neither.

IMO you should use Is prefix. It is somewhat recommended.

So I would go for IsModifiable

See this thread: Naming Conventions: What to name a boolean variable.

BrunoLM
+2  A: 

An instance that cannot be modified is read-only, no? So IsReadOnly?

Noel Abrahams
+2  A: 

CanModify is a perfectly good name, but it would be wrong in this scenario. When naming properties, you always have to think of typical usage.

MyClass widget;

if (widget.CanModify) { ... }

Clearly it is widget that is modifying something else. But you wanted to express whether the consumer can modify widget. So this name would be very very bad.

My preference in this case would be:

if (widget.IsWritable) { ... }

or

if (widget.IsReconfigurable) { ... }

depending on what exactly "modifying" the widget means.

But even

if (widget.CanBeModified) { ... }

would be much better than either CanModify or MayModify, both of which sound like they give widget permission to modify something else.

Ben Voigt
A: 
supercat