Abstract: Is it acceptable to include the type name in the variable name?
My scenario:
I am working with C# MVVM, and I have a lot of ICommand
properties in my ViewModel, named various things like GetSomething
, DoSomething
, WriteSomething
, etc. The "rule" for ordering members in C# is alphabetically, so I have my commands strewn throughout the file. Even if I sort them manually, it can be difficult to remember that GetSomething
is a ICommand
, especially when there are two methods for each command (the void
execute and the bool
can execute) and a MenuItem
the command is bound to (the menu is generated dynamically in code-behind).
I would like to name my commands CommandGetSomething
, in which case I could then have ExecuteGetSomething
, CanExecuteGetSomething
, and MenuItemGetSomething
so that all of the parts for the different commands are at least alphabetically next to each other (ExecuteDoSomething
would be next to ExecuteGetSomething
would be next to ExecuteWriteSomething
).
Am I even trying to solve the right problem here? The ViewModel has about thirty different commands, plus other stuff, so it is important that the file is ordered logically. I use ReSharper to sort the contents, and while I wish that I could sort by type name directly, the closest I can get is alphabetically (which is default).
Execute()
andCanExecute()
are actually executing, look at the concrete type that is being instantiated.