Generic Class Naming Convention

  • Thread starter Thread starter sloan
  • Start date Start date
S

sloan

I've noticed alot of people tacking on a "T" for a generic abled version of
an older class.

Ex:

1.1 Code

IDataStore


I take it, and while I keep IDataStore around for 2.0 version, I decide to
make a Generic version.

So I see this:

IDataStoreT < T >


Is that something that just developed? Or does it (the naming convention)
come from somewhere?


I've got Brad Abrams book here (Framework Design Guidelines) and it doesn't
speak to the classname specifically, only the parameter type <T>.


Thanks.
 
I would keep away from such naming. It's not necessary because the template
syntax and signatures are totlly different to those of the straight classes
and such indicative naming schemes are frowned upon, probably because the
schemes change so often that code that uses them can become either
unreadable or confusuing when modifications to the convention orrur.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Hi,


So I see this:

IDataStoreT < T >

Personally I do not like this naming, and I do not think is the recommended
Is that something that just developed? Or does it (the naming convention)
come from somewhere?

I've got Brad Abrams book here (Framework Design Guidelines) and it
doesn't speak to the classname specifically, only the parameter type <T>.


That is the way you commonly speak about generics, T is used to denote any
type.
 
Thanks Ignacio and Bob.

Yeah, I got this "this ain't right" feeling.

I'll convert my code and nix the IDataStoreT
 
Bob Powell said:
I would keep away from such naming. It's not necessary because the template
syntax and signatures are totlly different to those of the straight classes
and such indicative naming schemes are frowned upon, probably because the
schemes change so often that code that uses them can become either
unreadable or confusuing when modifications to the convention orrur.


I'm still using .Net 2003 :)

Say you have your own class named "Collection". Can you create a new type
under the same namespace with the same name for a generic, "Collection<T>"?
If not (and Collection was an actual named class that described both
completely with the exception of one is generic), what would you name the
"New" generic "Collection<T>"?

Thanks,
Mythran
 
sloan said:
I've noticed alot of people tacking on a "T" for a generic abled version of
an older class.

Ex:

1.1 Code

IDataStore

I take it, and while I keep IDataStore around for 2.0 version, I decide to
make a Generic version.

So I see this:

IDataStoreT < T >

You can still keep IDataStore and have IDataStore<T>. Type names can
effectively be "overloaded" by number of type parameters.

Can you give us some examples of where you've seen the "add a T" style?
I can't say I've come across it.
 
Mythran said:
I'm still using .Net 2003 :)

Say you have your own class named "Collection". Can you create a new type
under the same namespace with the same name for a generic,
"Collection<T>"? If not (and Collection was an actual named class that
described both completely with the exception of one is generic), what
would you name the "New" generic "Collection<T>"?

Thanks,
Mythran

Nevermind, I think. I believe Jon answered my question in his reply about 2
minutes after my message lol.

Mythran
 
Mythran said:
Say you have your own class named "Collection". Can you create a new
type under the same namespace with the same name for a generic,
"Collection<T>"? If not (and Collection was an actual named class that
described both completely with the exception of one is generic), what
would you name the "New" generic "Collection<T>"?

Yes, this works fine:

namespace Foo
{
public class Collection { }
public class Collection<T> { }
public class Collection<T1,T2> { }
}

So there's no need to name the generic ones CollectionT<T>. (And what
would you name the second generic one above anyhow? CollectionTT?)
 
Mythran said:
Say you have your own class named "Collection". Can you create a new type
under the same namespace with the same name for a generic, "Collection<T>"?

Yes, you can. Indeed, the System namespace in .NET 2.0 has the
Nullable<T> struct and the Nullable class.
 
Mythran said:
Nevermind, I think. I believe Jon answered my question in his reply about 2
minutes after my message lol.

But hey, that hasn't stopped me from answering it again ;)

(Note to self: read all messages before starting to reply...)
 
It was 2 code project things I downloaded.

So those 2 little things had too much power of influence on me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top