March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy wrote:
> Ivan Senji wrote:
>
>> Hasan Aljudy wrote:
>>
>>> I feel the same.
>>> I do come from C++ background, but I just hate templates! (Now I hate C++ itself :)
>>> I think templates were introduced in C++ to solve the "no-base-class" problem.
>>
>>
>>
>> It is the other way around, languages introduce common base class to solve the no-templates-problem. (Not a very good solution IMO).
>>
>
> No. The Object base class fits perfectly into the object oriented paradigm. Templates do not, hence a hack.
Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks.
And one more thing <insert what Lars replyed> :)
|
March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ivan Senji | "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com... > Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks. Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. |
March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com...
>
>>Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks.
>
>
> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics.
>
> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time.
>
>
Are you saying that all generics do is silently insert casts?
|
March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy wrote: > Walter Bright wrote: > >> "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com... >> >>> Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks. >> >> >> >> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. >> >> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. >> > > Are you saying that all generics do is silently insert casts? I think they'd have to be, considering Java and C# are both reliant upon serialization of code into JARs and assemblies. How would you serialize a template? -- Regards, James Dunne |
March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com...
>
>>Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks.
>
>
> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics.
>
> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time.
>
I knew that C# templates/generics are different from C++/D ones but didn't know how and why. Thanks. So C#/Java generics aren't as efficient as templates? That sucks.
|
March 05, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound@digitalmars.com> wrote in message news:dufcpn$p1n$2@digitaldaemon.com... > > "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com... >> Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks. > > Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. > > What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. I'm sure you're wrong about C#'s implementation using casts. Java generics do erase the type information and cast everything to an object. But the CLR was reworked to support generics so List<int> remains a list of ints until it's instantiated at runtime. |
March 06, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy wrote: > Walter Bright wrote: >> "Ivan Senji" <ivan.senji_REMOVE_@_THIS__gmail.com> wrote in message news:duf72h$f40$1@digitaldaemon.com... >> >>> Maybe so, but I see a common Object base class a hack to solve many problems that are simple and efficient to solve with templates. For example containers. Containers in Java(before templates)-style and C#(before templates)-style are nothing but inefficient hacks. >> >> >> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. >> >> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. >> > > Are you saying that all generics do is silently insert casts? For all interested, here's an article that explains the differences in more detail: http://www-128.ibm.com/developerworks/library/j-jtp01255.html This was posted in the NG by someone else that I don't recall, some time ago. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D |
March 06, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | "John C" <johnch_atms@hotmail.com> wrote in message news:dufl8l$14au$1@digitaldaemon.com... > "Walter Bright" <newshound@digitalmars.com> wrote in message news:dufcpn$p1n$2@digitaldaemon.com... >> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. >> >> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. > > I'm sure you're wrong about C#'s implementation using casts. Java generics do erase the type information and cast everything to an object. But the CLR was reworked to support generics so List<int> remains a list of ints until it's instantiated at runtime. From what I read, C# generics do not instantiate a new routine for every set of argument types, it implements *one* routine which handles them all via casting. |
March 06, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote: > "John C" <johnch_atms@hotmail.com> wrote in message news:dufl8l$14au$1@digitaldaemon.com... >> "Walter Bright" <newshound@digitalmars.com> wrote in message news:dufcpn$p1n$2@digitaldaemon.com... >>> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. >>> >>> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. >> I'm sure you're wrong about C#'s implementation using casts. Java generics do erase the type information and cast everything to an object. But the CLR was reworked to support generics so List<int> remains a list of ints until it's instantiated at runtime. > > From what I read, C# generics do not instantiate a new routine for every set of argument types, it implements *one* routine which handles them all via casting. It looks as though it has an optimisation for built-in types. http://www.artima.com/intv/generics2.html Clearly C# does it a lot better than Java does. Java generics seem to be 100% syntactic sugar. There's a valid point raised there about the cryptic error messages generated in C++ templates. Currently D error messages for templates are even worse, but this is mainly because it keeps tying to instantiate templates after one has failed (and you can't even press ctrl-c to stop the torrent, which can last for over a minute). This is another area where D could give a great improvement over C++. |
March 06, 2006 Re: Why Templates? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | "Don Clugston" <dac@nospam.com.au> wrote in message news:dugufa$2udq$1@digitaldaemon.com... > Walter Bright wrote: >> "John C" <johnch_atms@hotmail.com> wrote in message news:dufl8l$14au$1@digitaldaemon.com... >>> "Walter Bright" <newshound@digitalmars.com> wrote in message news:dufcpn$p1n$2@digitaldaemon.com... >>>> Technically, Java and C# implement generics, not templates. C++ and D implement templates, not generics. >>>> >>>> What's the difference? One way to think about it is generics are handled at run time (by casting), templates at compile time. >>> I'm sure you're wrong about C#'s implementation using casts. Java generics do erase the type information and cast everything to an object. But the CLR was reworked to support generics so List<int> remains a list of ints until it's instantiated at runtime. >> >> From what I read, C# generics do not instantiate a new routine for every set of argument types, it implements *one* routine which handles them all via casting. I just wanted to put the record straight. For reference types, the same code is shared, but full type information is maintained, and there's no Object-to-type cast. With value types and structs, separate sections of code are created to explicitly avoid boxing/unboxing. > > It looks as though it has an optimisation for built-in types. http://www.artima.com/intv/generics2.html There's a more technical overview here: http://research.microsoft.com/projects/clrgen/generics.pdf > > Clearly C# does it a lot better than Java does. Java generics seem to be 100% syntactic sugar. > > There's a valid point raised there about the cryptic error messages generated in C++ templates. Currently D error messages for templates are even worse, but this is mainly because it keeps tying to instantiate templates after one has failed (and you can't even press ctrl-c to stop the torrent, which can last for over a minute). This is another area where D could give a great improvement over C++. > Yes, template error messages are notoriously difficult to decipher. Compilers need to address this. |
Copyright © 1999-2021 by the D Language Foundation