On 9/27/12, Michael Matz <m...@suse.de> wrote:
> On Wed, 26 Sep 2012, Lawrence Crowl wrote:
> > > A lower-case type name indicates to me a non-changing type,
> > > i.e. nothing that depends on a template.  In C we only had
> > > such types so we used lower-case names everywhere.  With C++
> > > and templates I think we should start using upper case for some
> > > very specific use cases, like first letter of dependend types.
> >
> > How would you distinguish them from template parameter names,
> > which by convention have an upper case first letter?
>
> I wouldn't.  If the distinction becomes so important that authors
> need to see the speciality immediately by having a different
> convention how to spell names, then I think we did something wrong,
> and we should simplify the code.
>
> > What about non-type dependent names?
>
> I'm not sure what you're asking.  Let's make an example:
>
> template <typename T>
> struct D : B<T>
> {
>   typedef typename B<T>::E E; // element_type
>   E getme (int index);
> }

Inside that struct, lets say we have a field of type E.  Do we name
it F or f?

> In fact, as B<T>::E would probably be defined like "typedef
> typename T E", I would even have no issue to call the above E
> also T.  The distinction between the template arg name and the
> typedef would be blurred, and I say, so what; one is a typedef
> of the other and hence mostly equivalent for practical purposes.
> (And if they aren't, then again, we did something too complicated
> with the switch to C++).
>
> > The advantage to following them is that they will surprise
> > no one.
>
> They will surprise everyone used to different conventions, for
> instance Qt, so that's not a reason.

Anyone using the standard library will not be surprised if we follow
the conventions of the standard library.  I'd guess that the number
standard library programmers outnumbers the Qt programmers by 100
to 1.  I'd guess that the number of Qt programmers that do not know
the standard library is a minority.

> > Do you have an alternate suggestion, one that does not confuse
> > template parameters and dependent names?
>
> Upper last character?  Just kidding :)  Too many detailed rules
> for conventions are the death of them, use rules of thumbs,
> my one would be "somehow depends on template args -> has upper
> character in name", where "somehow depends on" includes "is a".

Ah, but there is a problem.  That typedef name does not necessarily
depend on a template parameter.

It is common practice to have

struct Q
{
  typedef int E;
  E getme (int index);
};

and use it in exactly the same places you would use D<something>.

In fact, one place is in the hash table code we are discussing.
The hash descriptor type may not itself be a template.  I believe
that few of them will actually be templates.

So, if E implies comes from template, the implication is wrong.

If we were to follow C++ standard library conventions, we would call
it value_type.  That would be my preference.  However, if folks
want a shorter name, I'll live with that too.  But as it stands,
the current name is very confusing.

-- 
Lawrence Crowl

Reply via email to