Closed dmikis closed 6 years ago
I'd vote for TType
notation cause it:
I like Google's Java style guide with ending T
(e.g. FooT
)
StyleT extends Style
)Foo Type
Leading T
looks awkward, but consistently with other notations with leading letters, e.g. I
for interfaces. Of course, if we decided to use them.
After some consideration I've ended up preferring Google's option too. My motivation is that TFoo
is a clear homage to Hungarian notation and adopting that approach will raise a (rather incovinient:) question: why not do that everywhere. Whereas FooT
may be considered as shortened version of FooType
which makes sense for generic parameters.
I'm fine with the T postfix too
The PR was met with some friction. My understanding is that we have a consensus on necessity of suffix or prefix, we just need to choose one. Since that choice is purely stylistic I suggest we vote for it.
To make it easy we'll do that with comment reactions. React with 👍 to vote for TGenericParamter
and 👎 for GenericParameterT
.
Motivation for TGenericParameter
:
Looks more consistently with
IInterface
if a project chooses to adopt it and with prefix_
for private and protected properties.
Motivation for GenericParameterT
:
Easily reads as
Generic Parameter Type
, don't suggest usage of Hungarian notation (which we try to avoid).
/cc @dfilatov @ikokostya @vmit @makishvili @tarmolov @dodev @twoRoger
Why need explicitly specify that name is template parameter?
Why need explicitly specify that name is template parameter?
My best understanding is that it's convenient to distinguish them from all the other types in a module. However, adding something to a parameter name gives as a simple and reliable naming scheme that avoids conflicts.
After thinking some time, I can't make decision. I don't like required prefix or suffix for template parameters, but it can be used as ad hoc solution for original problem:
interface StyleExtractor<StyleType extends Style> { ... }
// or
interface StyleExtractor<TStyle extends Style> { ... }
So, for now I vote for don't specify this rule in style guide.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
There've been a discussion around our current naming rules for templates. @vmit suggests (IIUC) to adopt a rule that will allow to distinguish a template parameter in code.
The main concern is naming conflicts for constrained template parameters, i.e. the ones required to extend a type or implement a interface:
Here's
S
is a violation of our style guide. But it's difficult to come up with an alternative since the most sane one isStyle
but it's already taken:( In this particular example we can renameStyle
in import statement, but that's not a universal solution.During discussion we've looked at some other codebases and code styles to gather more input. Here's the findings:
T
to name of a parameter (but the one for C++ doesn't);T
,U
, etc orTType
.