On 5/19/2011 10:02 PM, Steven Schveighoffer wrote:
On Thu, 19 May 2011 09:43:14 -0400, Matthew Ong <on...@yahoo.com> wrote:


According to Jonathan,
In the case of template mixins, you're essentially copying and pasting code. Yes. Liked what you said, with optimization at compiled time.

I am not trying to ask D to use JVM. (Please Note, that is why I choose D and also Go for the system level programming over C++ or Java JFFI.


Java does *not* use templates, they are generics. A generic seems like,
but is vastly different from a template.

A template *re-generates* the code as if you substituted the type for
the given template parameter.

A generic generates one object code file with a base class, and then
simply enforces the type constraints at compile time when *using* the
generic. Under the hood, the generic is compiled with the base class as
the given type. It probably avoids doing any type checking at runtime as
well (since it knows the compiler will check the type for it).
Can someone really say why this is a bad bad idea for memory with some automated
plumbing being done like in ActiveX.


The huge advantages of templates over generics are:
Yes. I do agree that template are NOT exactly generics,


1. The generated type can be fully optimized (footprint and code) for
the given type parameters.
Yes. All compiler from source to binary has some sort of binary optimization. That is a really good thing. Javac has also those feature.
Please do as much optimization as D can be.

2. You can execute different code paths depending on the parameter types.
3. You do not have to select a common base class/interface for a group
of types. That is, you can select any set of types that will work with
your template. With generics, all possible types need to have a common
base.
That is a good good thing to have, it allows the runtime binary to be reduced in time where only the data type is different. I understand that Java has a JVM to do that but I believe similar thing has been also
proven by ActiveX/Com+/DCom. I think they termed it Object Brokering.

4. Boxing/unboxing is not necessary for non-object types.

The advantage of generics are that you only have one compiled version.
This is actually very important for bytecode-based languages such as
Java and C#.
But perhaps some location about dynamic loading and unlaoding of DLL be part of D automatically. That is proven technology in the Linux Kernel for Device
Driver module.


LinkedList<String> list=new LinkedList<String>();
LinkedList<Integer> list=new LinkedList<Integer>();

// Can also apply for Account.
LinkedList<Account> list=new LinkedList<Account>();


But there is a single LinkedList Class File(single binary).

Yes, it's a LinkedList with the type given as Object.

-Steve


--
Matthew Ong
email: on...@yahoo.com

Reply via email to