|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.dtl - Minor gripe with template programming...
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... Jul 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... Jul 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. Jul 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 Jul 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 Jul 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 Jul 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... Jul 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 Jul 30 2004
I tend to use mixed-case-first-letter-upper-case (eg FooBar) for types and mixed-case-first-letter-lower-case (eg fooBar) for functions. I think the "D style guide" has the same rules. And I can't think of a good reason why template parameters should be treated any differently from anything else. All-caps (eg FOOBAR) means const or preprocessor symbol. Looking at my STL include headers on my RedHat 9 distro they use things like template<typename _InputIterator> ... and template<typename _Key, typename _Val, ...> so aside from milliions of _ floating around it is semi-readable. Matthew wrote: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... Jul 30 2004
Ben Hinkle wrote:Looking at my STL include headers on my RedHat 9 distro they use things like template<typename _InputIterator> ... and template<typename _Key, typename _Val, ...> so aside from milliions of _ floating around it is semi-readable. Jul 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... Jul 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... Jul 30 2004
In article <ceeju2$8bp$1 digitaldaemon.com>, Gold Dragon says...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; Jul 30 2004
Sean Kelly wrote:In article <ceeju2$8bp$1 digitaldaemon.com>, Gold Dragon says...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; Jul 31 2004
Gold Dragon wrote:Well, is it better than having nothing to tell what type the variable is at all? My teachers have pounded it into my skull with a cast iron to name my variables as describtive as possible but I would still like to know what type I'm dealing with. The projects that I work with aren't that big. What do you use? I'm all for protocol and paradigm but damn, it does get old. Jul 31 2004
Gold Dragon schrieb: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 Aug 02 2004
Gold Dragon wrote: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; Aug 03 2004
|