Framework Design Guidelines on Names of Generic Type Parameters

Continuing in the series of discussing topics from the Framework Design Guidelines… The last post generated some good discussion on generic type parameter naming I though I’d include this. 

 

 

Names of Generic Type Parameters

Generics are a major new feature of the .NET Framework 2.0. The feature

introduces a new kind of identifier called type parameter. The following

guidelines describe naming conventions related to naming such 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 the parameter.

For example, a parameter constrained to ISession might be called

TSession.

 

What do you think?  Have you started using generics heavily enough yet to form a solid opinion on this?