Convention for Filenames of Generic Classes

后端 未结 11 1125
广开言路
广开言路 2020-12-08 00:20

I want to be able to distinguish between a generic and regular (non-generic) version of a class. Much like the .NET framework does with it\'s generic and non-generic version

11条回答
  •  无人及你
    2020-12-08 00:52

    Just found this question after looking for what conventions other people use for generic class filenames.

    Lately I've been using ClassName[T].cs. I really like this convention, and I think it's superior to the others for the following reasons:

    • The type parameters jump out at you a little more than they do with the Microsoft convention (e.g., ClassNameOfT.cs).
    • It allows you to have multiple type parameters without too much confusion: Dictionary[TKey, TValue].cs
    • It doesn't require you to create any special folders, or to have your generic classes in a special namespace. If you only have a few generic classes, having a special namespace dedicated to them just isn't practical.

    I borrowed this convention from Boo's generic syntax, albeit slightly modified (Boo uses ClassName[of T]).

    Some developers seem to have a phobia of filenames that contain anything but letters and underscores, but once you can get past that this convention seems to work extremely well.

提交回复
热议问题