After receiving lots of feedback from internal and external community (see here for example), we decided to modify the generic type parameter naming guidelines. The previous guidelines allowed only single letter type parameter names. The new guidelines allow and even encourage descriptive names.

 

Here are the new guidelines.

Names of Generic Type Parameters

Do name generic type parameters with descriptive names, unless a single letter name is completely self explanatory and a descriptive name would not add value.

   public interface ISessionChannel<TSession> { … }

   public delegate TOutput Converter<TInput,TOutput>(TInput from);

   public class List<T> { … }

Consider using T as the type parameter name for types with one single letter type parameter.

   public int IComparer<T> { … }   

   public delegate bool Predicate<T>(T item);

   public struct Nullable<T> where T:struct { … }  

Do prefix descriptive type parameter names with “T”.

   public interface ISessionChannel<TSession> where TSession : ISession {

      TSession Session { get; }

   }

Consider indicating constraints placed on a type parameter in the name of parameter. For example, a parameter constrained to ISession may be called TSession.

 

Also, the BCL team is now considering several renames to the BCL generic types. We are still counting votes and it’s too close too call :-), but here is the provisional list:

 

  • EventHandler<T> : new name EventHandler<TEventArgs>
  • Converter<T,U> : new name Converter<TInput,TOutput>
  • Dictionary<K,V>, IDictionary<K,V>, KeyValuePair<K,V>, SortedDictionary<K,V>, SortedList<K,V> : new name something like Dictionary<TKey,TValue>. (same with all the related nested collections and enumerators)
  • KeyedCollection<K,T> : new name KeyedCollection<TKey,TItem>

 

I would like to thank all of those who provided feedback on this issue.

Thanks!