Jump to page: 1 2
Thread overview
Minor gripe with template programming...
Jul 30, 2004
Berin Loritsch
Jul 30, 2004
Ben Hinkle
Jul 30, 2004
Berin Loritsch
Jul 30, 2004
Ben Hinkle
Jul 30, 2004
Berin Loritsch
Jul 30, 2004
Sean Kelly
Jul 30, 2004
Matthew
Jul 30, 2004
Sean Kelly
Jul 31, 2004
Ben Hinkle
Jul 31, 2004
Sean Kelly
Jul 30, 2004
Matthew
Jul 30, 2004
Gold Dragon
Jul 30, 2004
Sean Kelly
Jul 31, 2004
Gold Dragon
Jul 31, 2004
Sean Kelly
Aug 02, 2004
Ilya Minkov
Aug 03, 2004
Berin Loritsch
July 30, 2004
This is something that has always been a gripe of mine with most
examples of template/generic programming: why do people insist on
using just one character for the type?  Take for example your
typical map:

Map!(K key, V value)

or worse:

Map!(K k, V v)

To me this is not really understandable.  Sure its generic, but
generic programming does support more than one character for
your type information.

Do you think it would be reasonable to use a type name that described
the role of the type in the template?  It really goes a long way into
making it more readable.  The Map would be written more like this:

Map!(KEY k, VALUE v)

or something like that.  I do like to make it clear that the types
are template types by the all caps or some other mechanism like this:

Map!(key_t key, value_t value)

However it feels most comfortable.

I am just sick of seeing functions, classes, etc. that just use one
letter for a generic type.  This is the greatest disservice that C++
STL has foisted on the poor unsuspecting developer.

For example, what is this function supposed to do?:

doSomething(T val, A!(T) acc, Map!(A!(T), T) map);


The name used for the type provides semantic clues to help understand
the code.  There should be no reason to write obfuscated code for D's
libraries.  At least, I hope I can influence DTL while it is still
young...
July 30, 2004
sure. sounds reasonable. I'll change my Map types to Key and Value and the List type from T to ...hmmm... Value. Now that you mention it it does seem wierd to have T in List and V in Map.

"Berin Loritsch" <bloritsch@d-haven.org> wrote in message news:cedkrk$2lu2$1@digitaldaemon.com...
> This is something that has always been a gripe of mine with most examples of template/generic programming: why do people insist on using just one character for the type?  Take for example your typical map:
>
> Map!(K key, V value)
>
> or worse:
>
> Map!(K k, V v)
>
> To me this is not really understandable.  Sure its generic, but generic programming does support more than one character for your type information.
>
> Do you think it would be reasonable to use a type name that described the role of the type in the template?  It really goes a long way into making it more readable.  The Map would be written more like this:
>
> Map!(KEY k, VALUE v)
>
> or something like that.  I do like to make it clear that the types are template types by the all caps or some other mechanism like this:
>
> Map!(key_t key, value_t value)
>
> However it feels most comfortable.
>
> I am just sick of seeing functions, classes, etc. that just use one letter for a generic type.  This is the greatest disservice that C++ STL has foisted on the poor unsuspecting developer.
>
> For example, what is this function supposed to do?:
>
> doSomething(T val, A!(T) acc, Map!(A!(T), T) map);
>
>
> The name used for the type provides semantic clues to help understand the code.  There should be no reason to write obfuscated code for D's libraries.  At least, I hope I can influence DTL while it is still young...


July 30, 2004
Ben Hinkle wrote:
> sure. sounds reasonable. I'll change my Map types to Key and Value and the
> List type from T to ...hmmm... Value. Now that you mention it it does seem
> wierd to have T in List and V in Map.
> 

It could be Element for the List/Vector elements.

It just seems that T is the substitute if there is only one type that
needed declaration, and it is counterintuitive in most cases.
July 30, 2004
"Berin Loritsch" <bloritsch@d-haven.org> wrote in message news:cednq6$2ni0$1@digitaldaemon.com...
> Ben Hinkle wrote:
> > sure. sounds reasonable. I'll change my Map types to Key and Value and
the
> > List type from T to ...hmmm... Value. Now that you mention it it does
seem
> > wierd to have T in List and V in Map.
> >
>
> It could be Element for the List/Vector elements.
>
> It just seems that T is the substitute if there is only one type that needed declaration, and it is counterintuitive in most cases.

I would prefer Value for List since it makes the signatures more uniform.
For example, the signatures for opIndex for List and Map, respectively, are
 Value opIndex(int n)
and
 Value opIndex(Key key)


July 30, 2004
Ben Hinkle wrote:

> "Berin Loritsch" <bloritsch@d-haven.org> wrote in message
> news:cednq6$2ni0$1@digitaldaemon.com...
> 
>>Ben Hinkle wrote:
>>
>>>sure. sounds reasonable. I'll change my Map types to Key and Value and
> 
> the
> 
>>>List type from T to ...hmmm... Value. Now that you mention it it does
> 
> seem
> 
>>>wierd to have T in List and V in Map.
>>>
>>
>>It could be Element for the List/Vector elements.
>>
>>It just seems that T is the substitute if there is only one type that
>>needed declaration, and it is counterintuitive in most cases.
> 
> 
> I would prefer Value for List since it makes the signatures more uniform.
> For example, the signatures for opIndex for List and Map, respectively, are
>  Value opIndex(int n)
> and
>  Value opIndex(Key key)

Sounds good to me.  I like this better than K,V,T,A, or whatever other
nonesense I have run accross.
July 30, 2004
If I see something like KEY, then I think of a global constant, or an enum member

I tend to use one, or at most two, letters for template params, and I don't see me changing. Sorry.

"Berin Loritsch" <bloritsch@d-haven.org> wrote in message news:cedkrk$2lu2$1@digitaldaemon.com...
> This is something that has always been a gripe of mine with most examples of template/generic programming: why do people insist on using just one character for the type?  Take for example your typical map:
>
> Map!(K key, V value)
>
> or worse:
>
> Map!(K k, V v)
>
> To me this is not really understandable.  Sure its generic, but generic programming does support more than one character for your type information.
>
> Do you think it would be reasonable to use a type name that described the role of the type in the template?  It really goes a long way into making it more readable.  The Map would be written more like this:
>
> Map!(KEY k, VALUE v)
>
> or something like that.  I do like to make it clear that the types are template types by the all caps or some other mechanism like this:
>
> Map!(key_t key, value_t value)
>
> However it feels most comfortable.
>
> I am just sick of seeing functions, classes, etc. that just use one letter for a generic type.  This is the greatest disservice that C++ STL has foisted on the poor unsuspecting developer.
>
> For example, what is this function supposed to do?:
>
> doSomething(T val, A!(T) acc, Map!(A!(T), T) map);
>
>
> The name used for the type provides semantic clues to help understand the code.  There should be no reason to write obfuscated code for D's libraries.  At least, I hope I can influence DTL while it is still young...


July 30, 2004
Please don't! Having mixed case identifiers would be the worst of all possibilities, since they could look like type (or function) names

"Ben Hinkle" <bhinkle@mathworks.com> wrote in message news:cedn96$2n8b$1@digitaldaemon.com...
> sure. sounds reasonable. I'll change my Map types to Key and Value and the List type from T to ...hmmm... Value. Now that you mention it it does seem wierd to have T in List and V in Map.
>
> "Berin Loritsch" <bloritsch@d-haven.org> wrote in message news:cedkrk$2lu2$1@digitaldaemon.com...
> > This is something that has always been a gripe of mine with most examples of template/generic programming: why do people insist on using just one character for the type?  Take for example your typical map:
> >
> > Map!(K key, V value)
> >
> > or worse:
> >
> > Map!(K k, V v)
> >
> > To me this is not really understandable.  Sure its generic, but generic programming does support more than one character for your type information.
> >
> > Do you think it would be reasonable to use a type name that described the role of the type in the template?  It really goes a long way into making it more readable.  The Map would be written more like this:
> >
> > Map!(KEY k, VALUE v)
> >
> > or something like that.  I do like to make it clear that the types are template types by the all caps or some other mechanism like this:
> >
> > Map!(key_t key, value_t value)
> >
> > However it feels most comfortable.
> >
> > I am just sick of seeing functions, classes, etc. that just use one letter for a generic type.  This is the greatest disservice that C++ STL has foisted on the poor unsuspecting developer.
> >
> > For example, what is this function supposed to do?:
> >
> > doSomething(T val, A!(T) acc, Map!(A!(T), T) map);
> >
> >
> > The name used for the type provides semantic clues to help understand the code.  There should be no reason to write obfuscated code for D's libraries.  At least, I hope I can influence DTL while it is still young...
>
>


July 30, 2004
In C++ my rule was:

- lowercase for types, variables, functions, etc.
- uppercase for preprocessor stuff
- mixed case for template parameters

but the D naming convention kind of tosses that out the window.  I've since slipped and now use template casing that corresponds to whatever I expect the thing to be.  So my template parameters are mostly mixed case now, with leading lowercase for aliases I expect to be functions.  Not ideal, but as D is less confusing as far as template readability is concerned I don't feel quite so evil doing this.


Sean


July 30, 2004
In article <cedp0u$2o8v$1@digitaldaemon.com>, Ben Hinkle says...
>
>
>"Berin Loritsch" <bloritsch@d-haven.org> wrote in message news:cednq6$2ni0$1@digitaldaemon.com...
>> Ben Hinkle wrote:
>> > sure. sounds reasonable. I'll change my Map types to Key and Value and
>the
>> > List type from T to ...hmmm... Value. Now that you mention it it does
>seem
>> > wierd to have T in List and V in Map.
>> >
>>
>> It could be Element for the List/Vector elements.
>>
>> It just seems that T is the substitute if there is only one type that needed declaration, and it is counterintuitive in most cases.
>
>I would prefer Value for List since it makes the signatures more uniform. For example, the signatures for opIndex for List and Map, respectively, are
> Value opIndex(int n)
>and
> Value opIndex(Key key)

See my iterator/list example at http://home.f4.ca/sean/d/iterator.d  That's exactly the convention I use there as the trailing "Type" bit that C++ tends to like just seems redundant since the D convention is that leading uppercase signals a type name anyway.


Sean


July 30, 2004
I think that I will apply this to whatever I do from now on but one problem I can think of is what if you have a constant of the same name? Yeah, scope will come in to play but what if you want to use the constant and not the template member? Constants could be written as

#   const int iKTOMB = 1024;

That would make unsigned with a ui, uc, etc. structs with st(_) and so on. That would give some readability to the overall code would templates be referenced with a 't', followed by the name? Seems interesting concept that goes against the paradigm that has govern programming since when people didn't have the liberty to use more than 16-64 characters for variable names (I would know nothing of that time since I was a little baby).

I do believe some programmers absolutely hate it with a passion that would force the said programmer into a rage destroying whole villages and such. I think they are the minority but with a big voice.


Berin Loritsch wrote:
> This is something that has always been a gripe of mine with most
> examples of template/generic programming: why do people insist on
> using just one character for the type?  Take for example your
> typical map:
> 
> Map!(K key, V value)
> 
> or worse:
> 
> Map!(K k, V v)
> 
> To me this is not really understandable.  Sure its generic, but
> generic programming does support more than one character for
> your type information.
> 
> Do you think it would be reasonable to use a type name that described
> the role of the type in the template?  It really goes a long way into
> making it more readable.  The Map would be written more like this:
> 
> Map!(KEY k, VALUE v)
> 
> or something like that.  I do like to make it clear that the types
> are template types by the all caps or some other mechanism like this:
> 
> Map!(key_t key, value_t value)
> 
> However it feels most comfortable.
> 
> I am just sick of seeing functions, classes, etc. that just use one
> letter for a generic type.  This is the greatest disservice that C++
> STL has foisted on the poor unsuspecting developer.
> 
> For example, what is this function supposed to do?:
> 
> doSomething(T val, A!(T) acc, Map!(A!(T), T) map);
> 
> 
> The name used for the type provides semantic clues to help understand
> the code.  There should be no reason to write obfuscated code for D's
> libraries.  At least, I hope I can influence DTL while it is still
> young...
« First   ‹ Prev
1 2