R – How verbose should names be for Model-View-ViewModel (MVVM) classes and instances

mvvmnamingnaming-conventionsverbosity

In general, I prefer to be verbose with .NET class and instance names, but some times (to quote Mike Woodhouse):

Over-verbosity tends to conceal syntax, and syntax is important.

The first place I felt like I really strayed into the over-verbosity regime is upon implementing the Model-View-ViewModel (MVVM) pattern in Silverlight and WPF apps.

For example, I start with an EnumerableRange model object:

public class EnumerableRange<T> : IEnumerable<T>
{ 
    public T Start{ get; set; }
    public T Stop{ get; set; }
    public long Count{ get; set; }
    ...
}

Then, I want to create a control that will allow me to surface this class for user input. Thus, I create a pair of view-related classes:

  1. an EnumerableRangeControlView UserControl (in XAML), and
  2. a POCO EnumerableRangeControlViewModel

Now, I use this pair in the parent View and ViewModel, respectively. With MVVM the view instance doesn't need a name, but my ViewModel instance is now named something like:

IndependentVariableEnumerableRangeControlViewModel.

Things are starting to get out of hand! What would you do?

Best Answer

I propose the following:

  1. Drop the word "Control" from View/ViewModel classes and instance names altogether. "View" and "ViewModel" clearly state the class purposes.

  2. (Optional) Consistently adopt a convention to post-fix ViewModel instances with "VM".

In the example above, the instance name

IndependentVariableEnumerableRangeControlViewModel 

becomes a much more readable

IndependentVariableEnumberableRangeVM