docs icon indicating copy to clipboard operation
docs copied to clipboard

Bad example

Open pshisbey opened this issue 1 year ago • 1 comments

The naming used in the following example from this page makes it confusing to understand.

public class Generic<T> { public T Field; }

The topic is generics, but naming the sample class "Generic" is confusing. Some may interpret it to mean that all generic classes must be named "Generic".

Instead, much clearer is to use arbitrary names such as:

public class foo<T> { public T bar; }

or something like:

public class myFileReader<T> { public T readLine; }

Sincerely Phil

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

  • ID: 0fc82239-30f3-14d2-ed23-5c0b66bd370e
  • Version Independent ID: 26fccd46-c489-1a05-2da2-dda3a8e5fac8
  • Content: Generics in .NET
  • Content Source: docs/standard/generics/index.md
  • Product: dotnet-fundamentals
  • GitHub Login: @adegeo
  • Microsoft Alias: adegeo

pshisbey avatar Jul 28 '22 00:07 pshisbey

@pshisbey I agree Generic is unnecessarily ambiguous. foo and bar are specifically forbidden. myFileReader is too specific. I think the following would be better:

public class MyGeneric<T>
{
    public T MyField;
}

Rick-Anderson avatar Jul 30 '22 01:07 Rick-Anderson

@gewarren I would like to work on this - please assign me so I have it on my list.

BartoszKlonowski avatar Jan 24 '23 15:01 BartoszKlonowski