December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Antti Sykäri | Yea, and PHP, where print "$foo"; prints the value of the variable foo ( interpolation they call it ) . C "Antti Sykäri" <jsykari@gamma.hut.fi> wrote in message news:slrnbsn8c6.17n.jsykari@pulu.hut.fi... > In article <bqfu00$1hlj$1@digitaldaemon.com>, Charles Sanders wrote: > > Cool idea! $ feels a little to much like 'interpolation' to me, but this > > sounds very cool ( if we want to keep the explicit , why do we want this again ? I dont use templates that much sry ) > > To me, $ feels for some reason like perl... > > -Antti > |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | Maybe slightly OT, but is there a reason that D doesn't support automatic deduction of types like C++ does? ie template swap(T){ void call(T a, T b){ } } would be nice if you could call it like instance swap(*).call(int,int) Which would deduce the type of the instance from the parameters. Or better yet, as someone said - remove the templating namespace and have call(int,int). Also, I do find the current template syntax slightly clunky, but could live with it if deduction was possible :) ie if something like , alias instance swap(*).call mySwap, was possible I'd be happier. Sorry if this is old ground. Cheers Brad |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | davepermen wrote: > i don't want to keep it explicit with a keyword or token. > oh, and i want to get rid of templates that are like namespaces. eighter we get > namespaces, and can add template parameters to it, or no namespaces at all. > namespaces or not, i want templates for functions, and for classes. > > instance Swap(int).call(a,b); is just plain stupid.. > > instance(int) swap(a,b); would be nice, for example.. > > but > > swap(a,b); is still unbeatable.... I agree completely, with all your points! The instance() form of instantiation is a nuisance that I never understood the need for. Is it just because the are no unambiguous parantheses "left"? I'm sure we can find some unused token to replace the <>! If you use templates a lot then all this "instance" stuff becomes starts getting on your nerves quickly. And it doesn't exactly make the code more readable either... Oh, and can't we please have implicit instantiation? This is a very powerful feature that goes a long way to enable you to enhance the built-in language facilities. Is it that hard to implement? And while I'm at it: the namespaces may sound nice in theory - making templates generic constructs that you can put almost anything into - but in practice they make the code less readable. For example, templates are most often used in collection classes. If you're writing a single collection class, then you face a naming problem: what should the name of the namespace be and then what do you call the class? If templates stay the way they are now, then I'm prediciting that we will see a lot of the following in D: template TLinkedList(T) { class TheClass { ... } } You have to give your class two names! One for that obligatory namespace and one for the class itself. And you have to specify both names when you use it ... pretty burdensome, if you ask me. And no, typedefs do not really provide much of a help here either, because it is in the nature of templates that they are written without knowing the types that they are going to be used with. So adding dozens of typedefs of the form typedef instance TLinkedList(int).TheClass TLinkedList_Int; typedef instance TLinkedList(MyClassA).TheClass TLinkedList_MyClassA; typedef instance TLinkedList(MyClassB).TheClass TLinkedList_MyClassB; is out of the question. Besides, the manual name mangling that would be required for such typedefs isn't exactly a property you'd expect from a modern language. There may be uses for template namespaces, but personally I never found myself wishing for that feature in C++. If the namespace was optional, then it would be a nice "icing on the cake" feature, but the way it is now it is a nuisance. Couldn't the template and class definition be merged? Like template class TLinkedList(T) { ... } as a synonym for template <currentnamespace>(T) { class TLinkedList { } } Hoping this post doesn't sound too negative. I just think these issues are too important for the language to just let them pass... Hauke |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Heretic | This is how templates should be declared: template(A, B, C) class Foo { public A a; public B b; public C c; } And this is how templates must be used: //explicit instantiation Foo(int, float, double) foo1; //implicit instantiation Foo foo2; foo.A = 5; foo.B = 5.3; foo.C = "yo"; Some notes: 1. since the template parameters are arguments to the template class, the syntax <identifier>(<type>) is perfectly justified. 2. In C++, the compiler deduces the types of a template function from its usage. It is possible to do so in classes also. 3. A template should not accept only values and types, but any expression that when it is used, it can be compiled. Templates should be more like parameterized macros. This would enable real generics. "Heretic" <Heretic_member@pathlink.com> wrote in message news:bqffep$q9u$1@digitaldaemon.com... > yo again. i`ve finally read the D language specification, lol. the more i read > bout d, the better it seems. however there`s one thing that annoys me. templates have to be instantiated with the "instance Name(ARG)" expression... i > dont quite like it, wouldnt it be better to use Name<ARG> ? it is still context > independent and much faster to type, more comfortable and stuff. in c++ i have a > function alias_cast<T>(char*) that works as a object reference. i add aliases to > objects, but not aliases in teh D way. i name objects with character strings and > i`m able to access them this way. in D, i`d have to write instance alias_cast(T).f(char*) whis is quite tedious to type and is less clear :/ maybe i`m missing something, pls correct me then, but consider my suggestion of > using the triangular braces for template instantiation... > > |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charles Sanders | IMO '$' should be reserved to denote the end of an array in the slice operation. SomeType array[ SOME_NUMBER ] ; array[0..$] ; /* slices the whole array */ array[$-2..$] /* slices the last three elements */ Mark. "Charles Sanders" <sanders-consulting@comcast.net> wrote in message news:bqg79k$1vpi$1@digitaldaemon.com... > Yea, and PHP, where print "$foo"; prints the value of the variable foo ( interpolation they call it ) . > > C > > "Antti Sykäri" <jsykari@gamma.hut.fi> wrote in message news:slrnbsn8c6.17n.jsykari@pulu.hut.fi... > > In article <bqfu00$1hlj$1@digitaldaemon.com>, Charles Sanders wrote: > > > Cool idea! $ feels a little to much like 'interpolation' to me, but > this > > > sounds very cool ( if we want to keep the explicit , why do we want this > > > again ? I dont use templates that much sry ) > > > > To me, $ feels for some reason like perl... > > > > -Antti > > > > |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Achilleas Margaritis | In article <bqg9nn$23m3$1@digitaldaemon.com>, Achilleas Margaritis says... > >This is how templates should be declared: > >template(A, B, C) class Foo { > public A a; > public B b; > public C c; >} > >And this is how templates must be used: > >//explicit instantiation >Foo(int, float, double) foo1; > >//implicit instantiation >Foo foo2; >foo.A = 5; >foo.B = 5.3; >foo.C = "yo"; I'd have that as Foo foo; foo.a = 5; foo.b = 5.3; foo.c = "yo"; The you could also have template(A, B, C) class Foo { public A aa; public A ab; public B b; public C c; } and Foo foo; foo.aa = 5; foo.ab = 49; foo.b = 5.3; foo.c = "yo"; |
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark J. Brudnak | In article <bqgclt$2843$1@digitaldaemon.com>, Mark J. Brudnak says... > >IMO '$' should be reserved to denote the end of an array in the slice operation. > >SomeType array[ SOME_NUMBER ] ; > >array[0..$] ; /* slices the whole array */ >array[$-2..$] /* slices the last three elements */ > >Mark. IMO you opinion is realy cool. Ant |
December 01, 2003 Re: $ as array end token (was template instantiation) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark J. Brudnak | >IMO '$' should be reserved to denote the end of an array in the slice operation.
>
>SomeType array[ SOME_NUMBER ] ;
>
>array[0..$] ; /* slices the whole array */
>array[$-2..$] /* slices the last three elements */
>
>Mark.
why? nothing is shorter than $. and i really mean NOTHING! :D
array[x..] == your array[x..$]
array[..x] == your array[0..x]
array[..] == your array[0..$] == array[]
would be best..
|
December 01, 2003 Re: template instantiation (suggestion) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hauke Duden | In article <bqg9gu$23bd$1@digitaldaemon.com>, Hauke Duden says... >davepermen wrote: >> instance Swap(int).call(a,b); is just plain stupid.. >> instance(int) swap(a,b); would be nice, for example.. >> but >> swap(a,b); is still unbeatable.... > >I agree completely, with all your points! I think this would be a great step towards real genericity in practice! I wonder, would this be unreasonably hard to implement? >The instance() form of instantiation is a nuisance that I never understood the need for. Is it just because the are no unambiguous parantheses "left"? I'm sure we can find some unused token to replace the <>! If you use templates a lot then all this "instance" stuff becomes starts getting on your nerves quickly. And it doesn't exactly make the code more readable either... For all I know, this instance() thing may have been a natural consequence of templates originally having been a preprcessor- only thing. Genericity was so separate from the language and the compiler that it may have been only natural not to come to think of this as the ultimate goal at the time. >Oh, and can't we please have implicit instantiation? This is a very powerful feature that goes a long way to enable you to enhance the built-in language facilities. Is it that hard to implement? Implicit instantiation was another thing, IMHO, that just wasn't even theoretically possible when Stepanov was at it. I could bet my last penny on that it'd have been there right from the start, had they ever known how. |
December 02, 2003 Re: $ as array end token (was template instantiation) | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | "davepermen" <davepermen_member@pathlink.com> wrote in message news:bqgebg$2ank$1@digitaldaemon.com... > >IMO '$' should be reserved to denote the end of an array in the slice operation. > > > >SomeType array[ SOME_NUMBER ] ; > > > >array[0..$] ; /* slices the whole array */ > >array[$-2..$] /* slices the last three elements */ > > > >Mark. > > why? nothing is shorter than $. and i really mean NOTHING! :D > > array[x..] == your array[x..$] > array[..x] == your array[0..x] > array[..] == your array[0..$] == array[] > > would be best.. > What about the case: array[$-2..$] /* slices the last three elements */ in your notation? > |
Copyright © 1999-2021 by the D Language Foundation