DEV Community

Discussion on: Ever been stumped by <E>, <T>, <K, V> in OO language documentation?

Collapse
 
aminnairi profile image
Amin • Edited

Great article, never really had the courage to deep dive into Dart but I'll do one day for sure! One thing that bothers me when writing things like

class Cache<T> {}

and then reading later, or in a comment

T meaning Type

Is that often when you say meaning, it really means that you could have just written it full length and not say that (I'm not talking about you personnally, just this kind of convention in general). Why not just write directly

class Cache<CacheType> {
  public addItem(item: CacheType): void { /* ... */ }
  public getItems(): Array<CacheType> { /* ... */ }
}

So that it gets clearer for newcomers or people getting into this code someday. I like to think that my code is a form of art that another person will have to continue after me.

Collapse
 
creativ_bracket profile image
Jermaine

Hey Amin,

You can use multi-letter placeholders if you want, like the Microsoft docs, although they still prefixed the placeholder letters docs.microsoft.com/en-us/dotnet/cs...

Personally I would be careful doing CacheType as that feels like there is a class CacheType somewhere, especially looking at addItem(item: CacheType)

Collapse
 
aminnairi profile image
Amin

I see, hence the prefix like TCache. I never really understood that until now. Thanks Jermaine!

Thread Thread
 
creativ_bracket profile image
Jermaine

You're welcome Amin.