Re: How to use interface template? How to model interface template properly in D.

2011-05-27 Thread Matthew Ong

On 5/27/2011 2:48 PM, Matthew Ong wrote:

On 5/27/2011 2:32 PM, Jacob Carlborg wrote:

Thanks very much.

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



Re: How to use interface template? How to model interface template properly in D.

2011-05-27 Thread Matthew Ong

On 5/27/2011 2:48 PM, Matthew Ong wrote:

On 5/27/2011 2:32 PM, Jacob Carlborg wrote:

On 2011-05-27 07:55, Matthew Ong wrote:

Never mind, I found it.
http://www.dsource.org/projects/tutorials/wiki/InterfaceTemplateExample


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



Re: How to use interface template? How to model interface template properly in D.

2011-05-26 Thread Matthew Ong

On 5/27/2011 2:32 PM, Jacob Carlborg wrote:

On 2011-05-27 07:55, Matthew Ong wrote:




In D the syntax for declaring a template and instantiate a template is
not the same. Have a look at the first example of
http://www.digitalmars.com/d/2.0/template.htm
If don't understand after reading that example please ask again, I don't
want to just give away the answer. You'll learn more by reading the
documentation and figuring it out by yourself.


Hi Jacob,

> In D the syntax for declaring a template and instantiate a template 
is  not the same.

I do understand that declaring is with () and instantiate is !().
That is the reason that I am asking
// ### or IS IT: DefType1!(T1) ??
RetVal1(T1) obj = new RetVal1(T1)(); // ### or IS IT: new RetVal1!(T1)();

I read that document. There are little but no practical model.

Is there any such syntax being used within the probos lib?


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



Re: What is the design reasons for Not considering base class overloaded

2011-05-26 Thread Matthew Ong

On 5/27/2011 2:03 PM, Matthew Ong wrote:

Would not it be a better keyword such as:

class A{
// assuming there is a new keyword of noinherit
noinherit void foo(int x){} // all other method can be inherited in A
except for this class
}
Ignore the last message on new noinherit, just remember we already have 
final.
Could new keyword help function hijacking and prevented aliasing all 
over the place??


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



Re: What is the design reasons for Not considering base class overloaded

2011-05-26 Thread Matthew Ong

On 5/25/2011 5:43 PM, bearophile wrote:

alias A.foo foo;  // ### Why the extra steps is needed for the compiler
to 'know' overloaded functions from base classes?


Others have already answered. I also suggest you to compile your code using the 
-w switch when possible.

Bye,
bearophile


>That is to prevent silently changing the program's behavior. b.foo(1) 
>could happily be a call to B.foo(long) today. Imagine one of the base 
>classes changed and now there is A.foo(int). Then our b.foo(1) would 
>silently start calling that new function. That would cause a tough bug.

>Ali

Ok.. Just to protect a auto promotion error from a base class.

Would not it be a better keyword such as:

class A{
// assuming there is a new keyword of noinherit
noinherit void foo(int x){} // all other method can be inherited in 
A except for this class

}

If such an AliasDeclaration is not used, the derived class's functions 
completely override all the functions of the same name in the base 
class, even if the types of the parameters in the base class functions 
are different. If, through implicit conversions to the base class, those 
other functions do get called, an std.HiddenFuncError exception is raised: ?


What is the default encapsulations of a class functions? 
(public/private/package...)
I assume that the example shown here are public because they are used in 
function bar?


How about when the inheritance tree becomes deeper than 4? And more and 
more overloaded functions are in different classes?


Does it mean we have to do more alias at child class at the 
bottom?<

If I am not mistaken, in C++/Java. They will choose the most bottom up 
closes parameter type signature match.


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



How to use interface template? How to model interface template properly in D.

2011-05-26 Thread Matthew Ong

Hi All,

The main aim here is to find out how to model similar syntax within D.

Due to the nature of the architecture of the library that I have 
designed in Java and heavily leans towards interface generics.

It works well with java.

Yes. I am aware about Tuple to allow me to do multiple value return.
The point is Not about returning multiple, but how to moduel

public interface DefType1 { // Please note this is like interface 
template

public Throwable getError();
public T1 getValue();
public String getDesc();
}
// Elsewhere.

public class RetVal1 implements DefType1 {

private RetVal1() {
}

public static  RetVal1 make(T1 value) {
RetVal1 obj = new RetVal1();
obj.mValue = value;
return obj;
}

private Throwable mError;

public void setError(Throwable error) {
mError = error;
}

public Throwable getError() {
return mError;
}
private T1 mValue;

public T1 getValue() {
return mValue;
}
private String mDesc;

public String getDesc() {
return mDesc;
}
}

// Yet, else where
class Account{...}

 public static RetVal1 methodA(int num, String str) { // 
similar to Instantiation template

 ... // do something.
return RetVal2.make(num, str);
}

void main(string[] args){
  RetVal1 ret = methodA(1, "abc"); // some method call that return
  if(ret.getError()==null){
 Account acc=ret.getValue1();
 prnln("amount=" + acc.getAmount());
  }
}
http://www.digitalmars.com/d/2.0/template.html#Constraint
Struct, Union, and Interface Templates
...
Analogously to class templates, struct, union and interfaces can be 
transformed into templates by supplying a template parameter list.

However there is no example shown.
In D the syntax should more or less look similar:

interface DefType1(T1) { // No issue here
public:
Throwable getError();
T1 getValue();
String getDesc();
}

public class RetVal1(T1) : DefType1(T1) { // ### or IS IT: DefType1!(T1) ??
...
   public static RetVal1(T1) make(T1)(T1 value) { // static method template
RetVal1(T1) obj = new RetVal1(T1)(); // ### or IS IT: new 
RetVal1!(T1)();

obj.mValue = value;
return obj;
   }
...
}


public static RetVal1(Account) methodA(int num, String str) { //### How 
to do that?? Compilation error.

   Account acc=new Account();
   ... // do something.
   return RetVal2.(Account)make(ac); //### How to do that?? compilation 
error also

}

 RetVal1(Account) ret = methodA(1, "abc"); // Compilation error also.
  if(ret.getError()==null){
 Account acc=ret.getValue1();
 prnln("amount=" + acc.getAmount());
  }

Kindly show some compilable and working code sample.

Thanks very much.

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



Re: Any application shutdown hooks?

2011-05-26 Thread Matthew Ong



On 5/25/11, Steven Schveighoffer wrote:

If you want a static dtor that runs on every thread shutdown, use a

normal
static dtor. If you want one that runs on the entire application
shutdown, use a shared static dtor.


I saw some commits change a static dtor to a shared static dtor and
wondered what was that all about..

Thanks a lot for the all the comments and instructions shown here.

Perhaps writing a mixin at module where the main method is located will 
do that exactly.


others may be dll and could be unloaded and cause __dtor to be called.

Will try such direction. Thanks people.

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



Re: Any application shutdown hooks?

2011-05-25 Thread Matthew Ong

On 5/26/2011 12:23 AM, Andrej Mitrovic wrote:

On 5/25/11, Steven Schveighoffer  wrote:

If you want a static dtor that runs on every thread shutdown, use a normal
static dtor.  If you want one that runs on the entire application
shutdown, use a shared static dtor.


I saw some commits change a static dtor to a shared static dtor and
wondered what was that all about..

Thanks a lot for the all the comments and instructions shown here.

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



Re: Any application shutdown hooks?

2011-05-25 Thread Matthew Ong

On 5/25/2011 11:52 PM, Steven Schveighoffer wrote:


If you want a static dtor that runs on every thread shutdown, use a
normal static dtor. If you want one that runs on the entire application
shutdown, use a shared static dtor.

-Steve
Module Destructor: Cool feature that I can consider to use for other 
purpose.


>If you want one that runs on the entire application shutdown, use a 
>shared static dtor.
It is more like an entire application shutdown event. So I will be 
placing that at the same module dtor and file as the main(string[] args)

using template mixin.

That might work. I will test that out.

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



Re: Any application shutdown hooks?

2011-05-25 Thread Matthew Ong

On 5/25/2011 11:13 PM, Steven Schveighoffer wrote:

http://www.digitalmars.com/d/2.0/class.html#StaticDestructor

-Steve


Static Destructor maybe executed when the class is being unloaded GC?
Because this is a class level. It is more like the application level 
exit and such.


That is not really the same as:
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook%28java.lang.Thread%29


This is triggered when:
# The program exits normally, when the last non-daemon thread exits or 
when the exit (equivalently, System.exit) method is invoked, or


# The virtual machine is terminated in response to a user interrupt, 
such as typing ^C, or a system-wide event, such as user logoff or system 
shutdown.




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



Re: Any example of using these Special Tokens?

2011-05-25 Thread Matthew Ong

On 5/25/2011 5:45 PM, bearophile wrote:

Matthew Ong:


I am not able make use of these 3 special tokens to print something.

writefln("gshared: %s",__gshared);
writefln("thread: %s",__thread);
writefln("traits: %s",__traits);


They are keywords, so it's like writing:
writefln("traits: %s", for);



Would some like to show me how this is done??


What do you want to do?

Bye,
bearophile


Looking at if they are run time related debug variables, perhaps 
consider using them within a logging api.



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



Any application shutdown hooks?

2011-05-25 Thread Matthew Ong

Hi,

If I am writing a database library such as DSL, Data Service Layer, 
there is a need for me to do a good clean up for the connections/results 
sets/transactions that this library is currently handling.


How ever, if another library/package somewhere else calls for a


java.lang.Runtime#public void addShutdownHook(Thread hook)


How do code or what library to use?

can someone please provide a simple working D example for try out.

Of cause, in Even in Java there is event if some cleaning lady were to 
accidentally unplug the main socket of your server. :)



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



Any example of using these Special Tokens?

2011-05-25 Thread Matthew Ong

Hi,

I am not able make use of these 3 special tokens to print something.

writefln("gshared: %s",__gshared);
writefln("thread: %s",__thread);
writefln("traits: %s",__traits);


rc\Sample.d(128): expression expected, not '__gshared'
src\Sample.d(129): expression expected, not '__thread'
src\Sample.d(130): found ')' when expecting '('
src\Sample.d(130): __traits(identifier, args...) expected
src\Sample.d(132): found '}' when expecting ','
src\Sample.d(146): expression expected, not 'EOF'
src\Sample.d(146): found 'EOF' when expecting ','
src\Sample.d(146): expression expected, not 'EOF'
src\Sample.d(146): found 'EOF' when expecting ','
src\Sample.d(146): expression expected, not 'EOF'


Would some like to show me how this is done??

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



What is the design reasons for Not considering base class overloaded function?

2011-05-24 Thread Matthew Ong

Hi,

file:///D:/JDKs/D/dmd2/html/d/function.html

Virtual Functions

>All non-static non-private non-template member functions are virtual.
Not a problem here. This is to allow 
(global/structure/class/Interface)functions to be overridden by child 
class unlesss (final/sealed).


This may sound inefficient, but since the D compiler knows all of the 
class hierarchy when generating code, all functions that are not 
overridden can be optimized to be non-virtual.
Ok. Not an issue also. There are ways for compiler to trace the actual 
object being used


Function Inheritance and Overriding
A functions in a derived class with the same name and parameter types as 
a function in a base class overrides that function:

...

However, when doing overload resolution, the functions in the base class 
are not considered:

...
// ### Why Not? Since B is a subset of A, and within B 
itself methods inherited from A can be called.

  b.foo(1); // calls B.foo(long), since A.foo(int) not considered
...
To consider the base class's functions in the overload resolution 
process, use an AliasDeclaration:

...
alias A.foo foo;  // ### Why the extra steps is needed for the compiler 
to 'know' overloaded functions from base classes?

...
B b = new B();
b.foo(1);   // calls A.foo(int)
--
// ### most developer would expect that to be the case if >All 
non-static non-private non-template member functions are virtual.<
This seems to be self contradicting syntax. Even in scripting like bash 
and even the old awk, the path resolutions of a global functions uses 
the most newer/lasted defined automatically.

--

If such an AliasDeclaration is not used, the derived class's functions 
completely override all the functions of the same name in the base 
class, even if the types of the parameters in the base class functions 
are different. If, through implicit conversions to the base class, those 
other functions do get called, an std.HiddenFuncError exception is raised: ?
What is the default encapsulations of a class functions? 
(public/private/package...)
I assume that the example shown here are public because they are used in 
function bar?


How about when the inheritance tree becomes deeper than 4? And more and 
more overloaded functions are in different classes? Does it mean we have 
to do more alias at child class at the bottom?


If I am not mistaken, in C++/Java. They will choose the most bottom up 
closes parameter type signature match. Even in scripting


All this questions are meant to understand what is the rational behind 
such design syntax. There is no description in those pages.


How about interface function defination inheritance?? Aikkk
I do not expect interface should be deeply inherited.

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



Re: New syntax within DWT / 2.

2011-05-24 Thread Matthew Ong

On 5/24/2011 10:01 PM, Jacob Carlborg wrote:


The reason for the aliases is this:

class A {
void foo (int i);
}

class B : A {
void foo ();
}

To be able to call A.foo(int) from B you need to add an alias to it. In
D, unlike in Java, the methods in A and B will be in two different
overload sets.

Have a look at:
http://www.digitalmars.com/d/2.0/function.html#function-inheritance
Read the second and third examples.



>the methods in A and B will be in two different overload sets.
Thanks, I will look into it.
I think when it comes to memory only java class can be port over to D 
easier... Not too sure about the other like file/network, NIO and others.


I suppose I need to dig into the dsource site to see if there is any 
similar replacement for java's library X.


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



Re: New syntax within DWT / 2.

2011-05-24 Thread Matthew Ong

On 5/24/2011 10:13 PM, Andrej Mitrovic wrote:

It's not an unintended behavior of D, it's a fix for a problem that
could be common in C++.


Thanks very much for any code shown.

Thanks for the clarification.
I was not aware of this URL.
http://d-programming-language.org/
I am aware of this URL.
http://www.digitalmars.com/d/2.0/hijack.html
...
and everything is hunky-dory. As before, things go on, AAA Corporation 
(who cannot know about B) extends A's functionality a bit by adding 
foo(int):

...
Now, consider if we're using Java-style overloading rules, where base 
class member functions overload right alongside derived class functions. 
Now, our application call:

...
b.foo(1);   // calls A.foo(int), AAAEI!!!

Please let me know if that is not mis-leading way presenting if that is 
an intended feature.


Please remind yourself, if someone is new from Java and Java has no such 
problem because the virtual method invocation has works securely and 
stable for many many years in banks and other places. The problem that 
document shown:


As software becomes more complex, we become more reliant on module 
interfaces. (Java has absolutely no ambiguous and unstable confusion.)


So... Naturally I assume D is superior in desgin and does not has this 
issue.


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



Re: New syntax within DWT / 2.

2011-05-24 Thread Matthew Ong

Hi Andrej,

On 5/24/2011 7:13 PM, Andrej Mitrovic wrote:

Any module which imports *this* module will have access to
java.io.File and java.io.OutputStream.

Lets say you have module Foo which has a function that takes a
parameter who's type is defined in module Bar. If the user imports
Foo, he will also have to import Bar. Doing a public import Bar in Foo
saves the user from having to manually import all needed modules that
Foo depends on.

Understood. hmm...So, this is there to avoid the layout of java.io.all?
Because, if there is such all.d file within java.io module, it would 
have public import all classes with there?



Because you don't want to pull in all modules when the user imports
*this* module. If you did a public import to java.lang.all, any code
which imports your module will import the entire java.lang package
(Note: this is assuming java.lang.all does actually do a public import
to all modules in the java.lang package. This is merely a convention
by the way, there's no rules as to what an "all" module does.).

Understood.


No, static imports have nothing to do with memory. It simply means you
have to fully specify 'std.file' when accessing its symbols. If
std.file has a File struct, you have to use it via
"std.file.File", and not just "File".

Please explain more if possible with some example code.


The module system is quite flexible, you can read about it in the docs. ;)


   public override void write( int b ){ // is override a must keyword?
 ...
   }

Read about this in the Base Class Member Function Hijacking section
here: http://d-programming-language.org/hijack.html
Ok. The override has something to do with function 
hijack(feature/avoiding unintended behavior of import), the sound of the 
name give me the idea of unintended behavior of import within D.


How about this?
// How is this being used within the context of this class? What if 
there is another overloaded write signature?

alias java.io.OutputStream.OutputStream.write write;
alias java.io.OutputStream.OutputStream.close close;

http://hg.dsource.org/projects/dwt2/file/d00e8db0a568/base/src/java/io/ByteArrayInputStream.d 



8 alias java.io.InputStream.InputStream.read read;
9 alias java.io.InputStream.InputStream.skip skip;
10 alias java.io.InputStream.InputStream.available available;
11 alias java.io.InputStream.InputStream.close close;
12 alias java.io.InputStream.InputStream.mark mark;
13 alias java.io.InputStream.InputStream.reset reset;
14 alias java.io.InputStream.InputStream.markSupported markSupported;

What are these for? How is the alias works with override and NOT 
overloading?


http://d-programming-language.org/hijack.html
If >overloading< of foo between X and Y is desired, the following can be 
done:


alias X.foo foo;
alias Y.foo foo;

Where-else here, It has to do with ByteArrayInputStream inheriting and 
overriding from InputStream.


The documentation of D need to be more open and consolidated. From what 
I can see, it does seem to be ad-hoc build, rather than properly 
organized by design.



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



What are the reasons for this syntax??

2011-05-24 Thread Matthew Ong

Hi ALL,

Refering to these 2 URL:
http://hg.dsource.org/projects/dwt2/file/d00e8db0a568/base/src/java/io/FileOutputStream.d

// why the public here?
6 public import java.io.File;
7 public import java.io.OutputStream;
9 import java.lang.all; // I can understand this here.

13} else { // Phobos
   // Why the import needed static?
14 static import std.file;
15 static import std.path;
16}

// What is the purpose of using alias here?
20 alias java.io.OutputStream.OutputStream.write write;
21 alias java.io.OutputStream.OutputStream.close close;


http://hg.dsource.org/projects/dwt2/file/d00e8db0a568/base/src/java/io/ByteArrayInputStream.d

8 alias java.io.InputStream.InputStream.read read;
9 alias java.io.InputStream.InputStream.skip skip;
10 alias java.io.InputStream.InputStream.available available;
11 alias java.io.InputStream.InputStream.close close;
12 alias java.io.InputStream.InputStream.mark mark;
13 alias java.io.InputStream.InputStream.reset reset;
14 alias java.io.InputStream.InputStream.markSupported markSupported;

Thanks very much.

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



New syntax within DWT / 2.

2011-05-24 Thread Matthew Ong

Hi D Experts,

The reasons that I am asking these questions is to learn how to port a 
Java Library into D. The clear


I am new to D, Just less than 2 weeks. But experience in Java.

From
http://www.dsource.org/projects/dwt/wiki/Contributors
http://www.dsource.org/projects/dwt

I have some questions about

FileOutputStream.d
-
module java.io.FileOutputStream;

// Why Public
public import java.io.File;
public import java.io.OutputStream;

// Why No public
import java.lang.all;

version(Tango){
import TangoFile = tango.io.device.File;
} else { // Phobos
static import std.file;  // why static import?? Does it impact memory?
static import std.path;
}

public class FileOutputStream : java.io.OutputStream.OutputStream {

// How is this being used within the context of this class? What if 
there is another overloaded write signature?

alias java.io.OutputStream.OutputStream.write write;
alias java.io.OutputStream.OutputStream.close close;
...
 public override void write( int b ){ // is override a must keyword?
   ...
 }

}

ByteArrayInputStream.d there is also a bunch of alias defined but not used.


Thanks very much.
--
Matthew Ong
email: on...@yahoo.com



Re: Not true for Java about Function Hijacking.

2011-05-23 Thread Matthew Ong

On 5/23/2011 5:37 PM, Jonathan M Davis wrote:


Report errors on the website and online documentation in bugzilla:
http://d.puremagic.com/issues/ . Choose "D" (out of D, DStress, and
puremagic.com) to get to the correct bug report form, and select "websites" as
the component of the bug report. Bugs and enhancement requests that aren't
entered into bugzilla tend to get lost.

- Jonathan M Davis

Thanks Jonathan.

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



Re: How to break module into multiple file.

2011-05-23 Thread Matthew Ong

On 5/23/2011 3:58 PM, Timon Gehr wrote:

On 2011-05-23 00:09, Matthew Ong wrote:


Thanks everyone that gave some working model to a newbie from Java Space.

I found the working file layout model from dwt2
http://hg.dsource.org/projects/dwt2

There is a dwt2\base\src

Haha. That is exactly like what I am looking for.

Yes. The person made one module to one d file.
Super cool.

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



Extra Cool D NEWbie ( from java)

2011-05-23 Thread Matthew Ong

Hi ALL Java D Newbie,


http://www.dsource.org/projects/dwt

Do a Mercurial Hg Clone of:
hg clone http://hg.dsource.org/projects/dwt2

Once done. dwt2 will be the top level directory of that clone.

Look inside:
dwt2\base\src\java

There are many buildin java like classes written nicely in D language.

Who is the kind soul that did this???
--
Matthew Ong
email: on...@yahoo.com



Not true for Java about Function Hijacking.

2011-05-23 Thread Matthew Ong

Hi Digitalmars/Walter Bright,


http://www.digitalmars.com/d/2.0/hijack.html

This talk covers function hijacking, where adding innocent and 
reasonable declarations in a module can wreak arbitrary havoc on an 
application program in C++(maybe true) and Java(not true).


Since I have not done C++ for a long while, I am not going to comment 
about that. But Java I have to place this request for correction from 
DigitalMars.


javac(from sun) Compiler will complain if there is an ambiguous to link 
any indentifier that has the same signature for contructor, 
methods(static/overloaded/overriden)


Overload Sets
Java denys global functions. All functions/methods are within a single 
class. Within the same class, the overloaded methods cannot have the 
same signature.


public class MyClass{

public int myVal(){
}

public String myVal(){ // compiler will complain here as error and NOT 
warning.

}
}

Both the method identifier and zero param list makes a identical signature.

Derived Class Member Function Hijacking
IDE like Netbeans and does flag:

@override
public void myMethodA(){ // Say you did not use the override tag
}



Base Class Member Function Hijacking
to prevent the child class from stealing your implementation for this 
single method, do:


public final void myMethodA(){ // final == sealed in C#
}


That is shown clearly when you tries to import both this 2 classes 
within Java:

import java.util.Date;
import java.sql.Date;

public class MyTest{
public static void main(String[] args){
Date now=new Date(); // thinking that you are using 
java.util.Date;
}
}


Again, as a senior Java Developer since java jdk 1.1 I agrees D as a 
good replacement for C++ because of modern design and approaches.


Kindly correct that to avoid confusing the new Java to D developer.

There are also other run time intelligent build into JVM to avoid 
malicious hacker attack on such thing using class proxy & stub.


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



Re: How to interface with existing Java Code at the API level.

2011-05-23 Thread Matthew Ong

On 5/21/2011 11:27 PM, Robert Clipsham wrote:

On 21/05/2011 09:58, Jonathan M Davis wrote:

On 2011-05-21 01:04, Matthew Ong wrote:

Hi,

D has major potential to replace C/C++ at the system API level.
What I can see D is doing now is trying to glue to the existing C API
instead of replacing that OLD OLD language.

But it is too early to see if that is the case at the Business
Application level to replace enterprise level resources(like JMS/MQ, .

Because of this, D could be a strong enhancement:
1) to allow other VM base language to interface with the native layer of
the OS that they are sitting on.
2) hiding some implementation logic in pure machine binary.
3) speeding up some existing IO/Hardware interfacing that is not able
to be done by Java/C# directly.

I am not too sure how the D dll works completely, but I guess. The end
results would be same as a C dll. but how to figure out the header file
in the C compatible as that was written in D.

Then some example would needed to be provided

From what I can see, as a starting show case project.

https://github.com/wmeissner/jffi


The likely way to interface between D and Java would be to use a C (or
maybe
C++) interoperability layer in between them. I'm not sure that it can
realistically be done any other way at this point.

- Jonathan M Davis


As a side note, Bernard Helyer is working on import(Java) for his D
compiler, and I believe Andrei is trying to persuade him to port it to
work with dmd once he's done -
https://github.com/bhelyer/SDC/commit/41d54a7a1fc57c3745493ee69b2be7bb59dc04c6
- I believe that allows for import(Java) my.java.class;




Cool!!! Ruby took off with JRuby because someone done such work for 
calling java api within ruby. According to JRuby people, JRuby now is 
faster than Ruby.


That is from java into D and Not from D api into Java.
Many cross platform GUI program with using some Java and linked into dll 
written by D. I can see that this is NOT the approach for that project.


Will however take a look.

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



Re: Some help on Mixin Template at Class level.

2011-05-23 Thread Matthew Ong

On 5/23/2011 2:17 AM, Simen Kjaeraas wrote:

On Sat, 21 May 2011 11:40:22 +0200, Matthew Ong  wrote:


Using your code I have this error:

src\Sample.d(16): Error: undefined identifier btype, did you mean
template AType(string name,U,alias V)?
src\Sample.d(16): Error: mixin AType!("ClassB",string,_error_) does
not match template declaration AType(string name,U,alias V)

Could you please ensure it is compilable code and so that I can test
the template shown by you.


Sorry about that.


string ATypeGenerator( string name ) {
return "class " ~ name ~ " : ClassC {
private:
U value;
public:
this(){}
void print(){}
mixin V;
}";
}

mixin template AType( string name, U, alias V ) {
mixin( ATypeGenerator( name ) );
}

class ClassC {}

mixin template btype() {
void someFunction() {}; // Content of a class.
}

mixin AType!("ClassB", string, btype);

void main() {
ClassC r = new ClassB();
}


Thanks simen. I have solve that issue.

Someone also pointed out:

template mydef(string name){
}

mixin(mydef!("abc"));

The above are NOT shown up left hand side of that when we click on 
Language Reference

http://www.digitalmars.com/d/2.0/lex.html
And also here.
http://www.digitalmars.com/d/2.0/comparison.html

not the same as:
mixin template mydeff(T){
...
}

mixin mydeff!(string);

Some centralized documentation is needed for D.

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



Re: How to print unicode like: こ ん に ち は 世界

2011-05-23 Thread Matthew Ong

On 5/21/2011 7:42 PM, Andrej Mitrovic wrote:

Oh yeah cmd.exe doesn't really have that many font options. Personally
I use console2 from http://sourceforge.net/projects/console/ , which
has font options and nice things compared to cmd.exe. (It's really
just a GUI wrapper with some extras).

Thanks a lot mate. Will look into it.

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



Re: How to break module into multiple file.

2011-05-23 Thread Matthew Ong

On 5/21/2011 7:16 PM, Russel Winder wrote:

On Sat, 2011-05-21 at 04:35 -0400, Nick Sabalausky wrote:
[ . . . ]

Subversion handles multiple people editing the same file perfectly fine. But
Hg probably is better than SVN, overall. I've been a happy SVN user for a
long time, but even I'm starting to get won over by Hg. Of course, some
people like Git better than Hg (and some people like Hg better than Git).


And there is also Bazaar.


overall this method of D file layout is because of ability to use some 
sort of Source Control and not because of D cannot compile???


Funny...But going to be hard sell to management level people from the QA 
side that does not do coding.


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



Re: Some help on Mixin Template at Class level.

2011-05-21 Thread Matthew Ong

On 5/21/2011 5:12 PM, Simen Kjaeraas wrote:

On Sat, 21 May 2011 10:54:54 +0200, Matthew Ong  wrote:


mixin template AType(alias T, U, alias V){
class T : ClassC { // Class level Template


This gives you a class called T. You seem to want it to have the name
you pass as a string, in which case you have to use string mixins.


private:
U value;
public:
this(){}
void print(){}
mixin V;
} // End Class
}

class ClassC {}

mixin template btype() {
void someFunction() {}; // Content of a class.

}

mixin AType!("ClassB", string, btype);

void main() {
ClassC r = new ClassB();
}


As mentioned above, in order to use the name from the template parameter
you need to use string mixins. Here is how I would do it:

string ATypeGenerator( string name ) {
return "class " ~ name ~ " : ClassC {
private:
U value;
public:
this(){}
void print(){}
mixin V;
}";
}

mixin template AType( string name, U, alias V ) {
mixin( ATypeGenerator( name ) );
}

mixin AType!("ClassB", string, btype);

void main() {
ClassC r = new ClassB();
}



Hi, Thanks for the respond.
I am really new to D.
Using your code I have this error:

src\Sample.d(16): Error: undefined identifier btype, did you mean 
template AType(string name,U,alias V)?
src\Sample.d(16): Error: mixin AType!("ClassB",string,_error_) does not 
match template declaration AType(string name,U,alias V)


Could you please ensure it is compilable code and so that I can test the 
template shown by you.


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



Some help on Mixin Template at Class level.

2011-05-21 Thread Matthew Ong

Hi,

As the documentation at D ONLY shows template at functions level and 
also ONLY the content of a class but without the definition of a class.

Could this code be working? Or did I miss out some syntax.

mixin template AType(alias T, U, alias V){
class T : ClassC { // Class level Template
private:
U value;
public:
this(){}
void print(){}
mixin V;
} // End Class
}

class ClassC {}

mixin template btype() {
void someFunction() {}; // Content of a class.

}

mixin AType!("ClassB", string, btype);

void main() {
ClassC r = new ClassB();
}


  Build Commands:  
-od"bin"
-of"bin\TestTemplate.exe"

-I"src"

"src\Sample.d"

src\Sample.d(20): Error: undefined identifier ClassB, did you mean class 
ClassC?

src\Sample.d(20): Error: ClassB is used as a type

Thanks very much for helping out.

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



How to interface with existing Java Code at the API level.

2011-05-21 Thread Matthew Ong

Hi,

D has major potential to replace C/C++ at the system API level.
What I can see D is doing now is trying to glue to the existing C API
instead of replacing that OLD OLD language.

But it is too early to see if that is the case at the Business 
Application level to replace enterprise level resources(like JMS/MQ, .


Because of this, D could be a strong enhancement:
1) to allow other VM base language to interface with the native layer of 
the OS that they are sitting on.

2) hiding some implementation logic in pure machine binary.
3) speeding up some existing IO/Hardware interfacing that is not able
to be done by Java/C# directly.

I am not too sure how the D dll works completely, but I guess. The end 
results would be same as a C dll. but how to figure out the header file 
in the C compatible as that was written in D.


Then some example would needed to be provided

From what I can see, as a starting show case project.

https://github.com/wmeissner/jffi



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



Re: How to break module into multiple file.

2011-05-21 Thread Matthew Ong

On 5/20/2011 4:23 AM, Nick Sabalausky wrote:

"Matthew Ong"  wrote in message
news:ir3801$84b$1...@digitalmars.com...

On 5/14/2011 3:17 AM, Nick Sabalausky wrote:

"Jason House"   wrote in message



But yea, one-class-per-file is really a Java thing (and then a few other

Not true entirely, the limit is one public class per file. There is no
actual limit for such:
// The file must be ClassA.java

public class ClassA{}

class ClassB1{}
class ClassB2{}
class ClassB3{}
class ClassB4{}...







I see. But in any case, D allows multiple public classes in one file, FWIW.
Yes. I agree that the multiple public class per file is good. I can the 
uses of that when it does not come into library but in Web Page 
Rendering, Business Logic Layer and GUI Logic Layer(Java really messes 
thing up here for swing GUI.)






languages kind of ape'd it.). No need to force youself into that in D.


As for the real reason it is for:
That current D layout seem to limit that one file to a single developer.
Instead of multiple classes by multiple developers within the same module.

Using the example:
HashMap&  Unit tested implemented by matthew
LinkedList&  Unit tested implemented by john
but the same module is handled by Jonathan for other classes?



That's what version control systems are for. As long as you're using a VCS
that isn't terrible (ie, as long as you're not using CVS or Visual
SourceSafe), than it's easy for multiple people to edit the same source
file.
OK. I read somewhere else about this, I think there is same issue for 
SubVersion?

Someone suggested Hg.

But that does not work well for some security centric applications like 
where they divide up even the accountability of the developer to the 
code. How can someone proof that if multiple person changes the same 
peace of code. Like in Defence and Banking people might ask this questions.





But Nick,
-- ...to this: ---

// libfoo/all.d
module libfoo.all;
public import libfoo.partA;
public import libfoo.partB;
public import libfoo.partC;

That does the trick.


Great :)
The breaking up allow me to even hide some class that I do not want. I 
think I begin to understand how D does its package/module layout.
Using the approach that you shown here, allow me to think about how to 
migrate some of the Java API I have coded.





Now my only concern is that when does D linked like C++ or dynamic
selective linked on import that is ONLY really used and not linked ALL
that is importedSuch thing does not happen in Java because linking is
done during runtime by Class Loader. I wonder the loader in D for DLL is
as intelligent.



AIUI, automatic DLL loading is handled by windows, not D (but I think you
can also load DLLs manually). Also, D is usually linked statically, not
dynamically. I know it's possible for a static linker to eliminate code
that's not used, but I don't think OPTLINK (D's linker on windows) currently
does it.

Now. That is a feature request to be seriously look into.


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



Re: How to print unicode like: こ ん に ち は 世界

2011-05-21 Thread Matthew Ong

On 5/21/2011 2:46 PM, Matthew Ong wrote:

On 5/20/2011 2:55 PM, Russel Winder wrote:

On Thu, 2011-05-19 at 22:37 +0200, Andrej Mitrovic wrote:
[ . . . ]

You would also need a Unicode-aware font, maybe Lucida or something
similar. Typically fixed-point fonts used for programming have little
support for Unicode characters, and you would get back a black or
white box like "[]".


Alternatively use a nice proportional font with Unicode support for code
so it is more readable?

Backward compatibility with 80x24 terminals is just so last millennium.


Hi All,

Thanks for the example code on the unicode issue.

hi Andrej,
version(Windows)
{
import std.c.windows.windows;
extern(Windows) BOOL SetConsoleOutputCP(UINT);
}

void main()
{
version(Windows) SetConsoleOutputCP(65001);
writeln("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界");
}

I am running this on a M$ Vista Professional edition.

Unfortunately that code sample does not work... Please see attachment.

The reason I am testing this is to understand how the stream library works.

Console test is fundamental test to see if the language handles unicode
within the source code itself automatically and display them correctly
when it does file IO, network and also GUI level.

Normally in mordern languages it should, because that allow a developer
to easily define a simple resource bundle file to loaded automatically
within the same fragment of code. If not, then, there is going to be
problem. I hope we do not need to write such code:

version(English){
// some code
}version(Chinese_MainLand){
// some other code
}version(Chinese_HongKong){
// yet another code
}...etc

I have originally plan to send an attached screen shot but it is not
working for the newsgroup. Perhaps someone can show me how to do that here.


Hi All,
correction on my part. It does seem like a font issue. Strangely the 
same console program that used to be able to show unicode correctly for 
both java and go is no longer working???


I think it is true, it has nothing to do with D. More like a font thing.

The result I got working is within the Eclipse Java and Go Console but 
NOT the DDT D console.


Without IDE, all of them show garbage...
Perhaps some one can kindly show me how the console fonts setting works 
for M$ Vista.


>Unicode-aware font, maybe Lucida< How I tried Lucida it also does not 
work. There is only 2 fonts shown int the Command Prompt Properties Font 
Tab.


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



Re: How to print unicode like: こ ん に ち は 世界

2011-05-20 Thread Matthew Ong

On 5/20/2011 2:55 PM, Russel Winder wrote:

On Thu, 2011-05-19 at 22:37 +0200, Andrej Mitrovic wrote:
[ . . . ]

You would also need a Unicode-aware font, maybe Lucida or something
similar. Typically fixed-point fonts used for programming have little
support for Unicode characters, and you would get back a black or
white box like "[]".


Alternatively use a nice proportional font with Unicode support for code
so it is more readable?

Backward compatibility with 80x24 terminals is just so last millennium.


Hi All,

Thanks for the example code on the unicode issue.

hi Andrej,
version(Windows)
{
   import std.c.windows.windows;
   extern(Windows) BOOL SetConsoleOutputCP(UINT);
}

void main()
{
   version(Windows) SetConsoleOutputCP(65001);
   writeln("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界");
}

I am running this on a M$ Vista Professional edition.

Unfortunately that code sample does not work... Please see attachment.

The reason I am testing this is to understand how the stream library works.

Console test is fundamental test to see if the language handles unicode 
within the source code itself automatically and display them correctly 
when it does file IO, network and also GUI level.


Normally in mordern languages it should, because that allow a developer 
to easily define a simple resource bundle file to loaded automatically 
within the same fragment of code. If not, then, there is going to be 
problem. I hope we do not need to write such code:


version(English){
   // some code
}version(Chinese_MainLand){
  // some other code
}version(Chinese_HongKong){
  // yet another code
}...etc

I have originally plan to send an attached screen shot but it is not 
working for the newsgroup. Perhaps someone can show me how to do that here.


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



Re: How to 'add' functions to existing type/class/struct/interface...

2011-05-20 Thread Matthew Ong

On 5/19/2011 11:23 PM, Adam D. Ruppe wrote:

How to 'add' functions to existing type/class/struct/interface...


You don't. It seems to be that this would break encapsulation anyway.

Not entirely. As seen within JRuby and Go.
JRuby shown that the methods defined within java.lang.String are not 
corrupted and the new functions can also be entirely independent to 
String. But that is done with a lot of runtime plumbing within the JRuby
engine. I think they injected some bytecode using BSH to do that without 
touching the String.class file in JVM. Hence, I suspected it has nothing 
to do with breaking a library's encapsulation.


Not too sure about Go as it was designed from ground up to do this.

This block of comments is totally not related to this thread, but just 
to set the record straight.

--
Only data that you deem safe are expose. Go does not have public/private 
keyword, but they uses first letter of the Identifier of Functions or 
Variables to define encapsulation(strange+implied).


Uppercase first letter = Public.
lowercase first letter = Private.
--


I read from Adam that it is possible and is done within Phobos by D.
Could some one provide some sample code to explain that.


Look in std.range for full examples but here's a brief one:

Ok. Thanks.

void doSomething(T)(T item) if( isMyInterface!T ) {
  // use item here
}
template isMyInterface(T) {
  static if(is(typeof(
// write some code to test the interface here

 ... Do not know what is done here because I am new...

  )))
  enum bool isMyInterface = true;
  else
  enum bool isMyInterface = false;
}
Because I am new to D, That is a very strange syntax to me. I suppose 
the std.range example may give more clarity.




You can also use the template straight up, though that's less
structured:

auto doSomething(T)(T obj) {
  // write whatever you want here using obj
  // it won't compile if the obj doesn't match the used functions
}
This example is more like a static generics in Java for me. But it is a 
form of the polymorphic ability. It does not add



Or, you can go with a more strictly Go style by using method #1
and automating the isMyInterface detection. Kenju Hara wrote
an adaptTo function that does something like this:

interface Interface {
 void foo();
}


class A { // note it doesn't list the interface here
  void foo();
}

void func(Interface i) { }


A a = new A();

func(adaptTo!Interface(a));


I don't think this has been committed to Phobos yet though.
This last example fits the Go interfaces example the best. I think, but 
there is no code for adaptTo(T). There is no clear idea how this is done.


From what I can see Go is doing is like in C/C++:
1) using structure to define the data-type. // Class Object is more 
expensive.
2) static functions that bind to that structure datatype. Such static 
functions can be define within the LIB or introduced as new functions 
outside the library.

3) using some form of function pointer to call those static functions.

Hey Adam, you are one of the most experience D person that does give 
solid answer to experience developers from other language.



Thanks for the answer clarifying this.
--
Matthew Ong
email: on...@yahoo.com



Re: How to 'add' functions to existing type/class/struct/interface...

2011-05-20 Thread Matthew Ong

On 5/19/2011 11:23 PM, Adam D. Ruppe wrote:

How to 'add' functions to existing type/class/struct/interface...


You don't. It seems to be that this would break encapsulation anyway.
This block of comments is totally not related to this thread, but just 
to set the record straight.


Not entirely. Only data that you deem safe are expose. Go does not have 
public/private keyword, but they uses first letter of the Identifier of 
Functions or Variables to define encapsulation(strange+implied).


Uppercase first letter = Public.
lowercase first letter = Private.



I read from Adam that it is possible and is done within Phobos by D.
Could some one provide some sample code to explain that.


Look in std.range for full examples but here's a brief one:

Ok. Thanks.

void doSomething(T)(T item) if( isMyInterface!T ) {
  // use item here
}
template isMyInterface(T) {
  static if(is(typeof(
// write some code to test the interface here

 ... Do not know what is done here because I am new.

  )))
  enum bool isMyInterface = true;
  else
  enum bool isMyInterface = false;
}
Because I am new to D, That is a very strange syntax to me. I suppose 
the std.range example may give more clarity.




You can also use the template straight up, though that's less
structured:

auto doSomething(T)(T obj) {
  // write whatever you want here using obj
  // it won't compile if the obj doesn't match the used functions
}
This example is more like a static generics in Java for me. But it is a 
form of the polymorphic ability. It does not add



Or, you can go with a more strictly Go style by using method #1
and automating the isMyInterface detection. Kenju Hara wrote
an adaptTo function that does something like this:

interface Interface {
 void foo();
}


class A { // note it doesn't list the interface here
  void foo();
}

void func(Interface i) { }


A a = new A();

func(adaptTo!Interface(a));


I don't think this has been committed to Phobos yet though.
This last example fits the Go interfaces example the best. I think, but 
there is no code for adaptTo(T). There is no clear idea how this is done.


From what I can see Go is doing is like in C/C++:
1) using structure to define the data-type. // Class Object is more 
expensive.
2) static functions that bind to that structure datatype. Such static 
functions can be define within the LIB or introduced as new functions 
outside the library.

3) using some form of function pointer to call those static functions.

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



Re: How to print unicode like: こ ん に ち は 世界

2011-05-19 Thread Matthew Ong

On 5/19/2011 11:22 PM, Matthew Ong wrote:

Hi,

import std.stdio;
alias immutable(wchar)[] String;
String str="Hello, world; orΚαλημέρακόσμε; 
orこんにちは世界";
writeln(str); // It prints garbage on console.

In Java and Go, that just works. I believe UTF-X is handles that.

How to do that within D?

Yes. I am still new to D. No. I am not japanese but chinese.


Matthew Ong



String str="Hello, world; or Καλημέρα κόσμε; or こんにちは 世界";

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



Re: How to print unicode like: こ ん に ち は 世 界

2011-05-19 Thread Matthew Ong
AH... The web encoder corrupted the string. into NON human readable.


How to print unicode like: こ ん に ち は 世 界

2011-05-19 Thread Matthew Ong
Hi,

import std.stdio;
alias immutable(wchar)[] String;
String str="Hello, world; or Καλημέρα 
κόσμε; or こんにちは 
世界";
writeln(str); // It prints garbage on console.

In Java and Go, that just works. I believe UTF-X is handles that.

How to do that within D?

Yes. I am still new to D. No. I am not japanese but chinese.


Matthew Ong



How to 'add' functions to existing type/class/struct/interface...

2011-05-19 Thread Matthew Ong

Hi All/Walter Bright,

The ability is able to be model and done by JRuby and also Google Go.


Conversions
...
// this function is now available for the object type Sequence. Done 
outside of Sequence.d

func (s Sequence) MyFunction() string {
   //  My Function has access to all the public/internal data of the
   // Sequence here.
}
...
s Sequence;
s.MyFunction(); // now that can be used. Completelty new Function 
outside of Sequence.d


That is some how like JRuby ability to 'add' method into the java final 
String class without really touching that class String.


Interfaces and methods

Since almost anything can have methods attached, almost anything can 
satisfy an
interface. One illustrative example is in the http package, which 
defines the
Handler interface. Any object that implements Handler can serve HTTP 
requests.


It is not just entirely like java interfaces, but java has to somehow, 
code the api in a very strange pattern to support this.


I read from Adam that it is possible and is done within Phobos by D.
Could some one provide some sample code to explain that.

Mixin and Template does not quite fit there I think, in other 
language(Java/C#) are more for code reusing rather than code 'injection'.


Perhaps that is not the case within D as a limitation. Some code example 
would be really useful.




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



Re: How To Dynamic Web Rendering?

2011-05-19 Thread Matthew Ong

On 5/13/2011 4:01 AM, Nick Sabalausky wrote:

"Matthew Ong"  wrote in message
news:iqgo17$2nqv$1...@digitalmars.com...

Hi Adam,

Thanks again for the sharp pointed answer.

What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
some sort of dynamic web base development?



I use D for web work by using the standard CGI interface and>sometimes
an embedded http server. It's the best thing I've ever used.

Could you share how or show an URL that provide sample code to do that in
D?



How to also code digitally sign the DLL  that was compiled in D?

The same way you sign any other dll/exe.
So we use external tool to do that and not a build in one??
In java, we use jarsigner with some keygen.

Please bear in mind I am new to D.



Here's a basic "Hello world" CGI app in D:

// hellocgi.d
import std.conv;
import std.stdio;

void main()
Hmm...Might be problem for it to be main... Security concerned because 
of the publicity done my M$ and others also. When they pushed for ASP/JSP...

{
 // Read in HTTP request headers
 string[] requestHeaders;
 while(true)
 {
 string line = readln();
 if(line.length<= 1)
 break;

 requestHeaders ~= line;
 }

 // Send response headers
 writeln("Status: 200 OK");
 writeln("Content-Type: text/html; charset=UTF-8");
 writeln();

 // Send content
 writeln("Hello world");
}

Compile with:
dmd hellocgi.d

And just stick the resulting "hellocgi.exe" (windows) or "hellocgi" (other)
in whatever "cgi-bin"-capable directory you have on your server.

Thanks for this Example also. I will keep it for later trial.


Everything else (such as fancy CGI libraries/frameworks like Adam's) can
ultimately be built out of that basic idea.

Keep in mind though, that since D is natively compiled, you'll have to
compile it on either the same OS and CPU architecture as your server, or an
OS/CPU that's compatible with your server. (This would be true of C/C++ as
well.)

yes. I am aware about that. Thanks very much.

I'm sure it's possible to make an ISAPI filter or Apache module in D, but
I've never really done that in any langauge, and I haven't really dealt with
DLLs much, so I wouldn't know how. But even as CGI, a web app in D is likely
to still be much faster than one in, for instance, PHP or Ruby.
Why I am looking for DLL as compare to exe is becuase it is a well know 
security concern

published and accepted as minimum by the industry for MNC.


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



Re: Can someone explain how mixin is implemented?

2011-05-19 Thread Matthew Ong

On 5/19/2011 10:02 PM, Steven Schveighoffer wrote:

On Thu, 19 May 2011 09:43:14 -0400, Matthew Ong  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 list=new LinkedList();
LinkedList list=new LinkedList();

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


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



Re: (Windows) beginner woes....

2011-05-19 Thread Matthew Ong

On 5/19/2011 9:43 PM, Lloyd Dupont wrote:

1]. ok, I unzipped dmd.zip and dm.zip. what's this dm.zip for?

2]. I install Visual D, I had to point it to the DMD folder. And it did
compile my 1st D program fine... doubly wondering what's dm for?

3]. I try installed DFL. Actuall it unzipped in the worng forlder, so I
moved whateve in unpacked i the right folder. Made a form with entice
designer, copied the code in Visual D (i.e. Visual studio with support
for D) and tried to compile. It complain that "all.d" is missing. Why
does it need a source file? I though the .lib file contained all
necessary info and gone were the headers file!
+ how can I fix that?


To summarize I'm quite confused by the directory structure, where do I
install .lib file, why do I need an import directory



Also, lastly, how do I compile 32bit or 64bits? I want to target 32 bits
for sure! (even though I'm on a 64 bits machine!)

Currently, I am using Eclipse and DDT
According to Mafi. Under Re: Making D Lang More easy. (d.D forum)
For Eclipse there is for example DDT and there are VisualD and Descent.
http://code.google.com/a/eclipselabs.org/p/ddt/

Version: Helios Service Release 2
Build id: 20110218-0911

That solve most of my path issue.

-od"bin"
-of"bin\TestD.exe"

-I"src" // where all my source file are located.

"src\cc\Lang\EMPTY.d"
"src\cc\Lang\all.d"
"src\main.d"


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



Re: import problem

2011-05-19 Thread Matthew Ong

On 5/19/2011 9:49 PM, Lloyd Dupont wrote:

so I copied the Entice generated UI code in Visual D, and tried to compile.
I got 1 error:
Error 1 Error: module all is in file 'dfl\all.d' which cannot be read
C:\Dev\DTest\DTest1\myform.d 7

On
import dfl.all;

For info I do have dfl.all in
C:\D\dmd2\windows\import\dfl
Welcome to D. Read some of my threads about breaking module into 
multiple files.


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



Re: How to break module into multiple file.

2011-05-19 Thread Matthew Ong

On 5/14/2011 3:17 AM, Nick Sabalausky wrote:

"Jason House"  wrote in message


> But yea, one-class-per-file is really a Java thing (and then a few other
Not true entirely, the limit is one public class per file. There is no 
actual limit for such:

// The file must be ClassA.java

public class ClassA{}

class ClassB1{}
class ClassB2{}
class ClassB3{}
class ClassB4{}...


> languages kind of ape'd it.). No need to force youself into that in D.

As for the real reason it is for:
That current D layout seem to limit that one file to a single developer. 
Instead of multiple classes by multiple developers within the same module.


Using the example:
HashMap & Unit tested implemented by matthew
LinkedList & Unit tested implemented by john
but the same module is handled by Jonathan for other classes?

But Nick,
-- ...to this: ---

// libfoo/all.d
module libfoo.all;
public import libfoo.partA;
public import libfoo.partB;
public import libfoo.partC;

That does the trick. Now my only concern is that when does D linked like 
C++ or dynamic selective linked on import that is ONLY really used and 
not linked ALL that is importedSuch thing does not happen in Java 
because linking is done during runtime by Class Loader. I wonder the 
loader in D for DLL is as intelligent.



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



Re: Can someone explain how mixin is implemented?

2011-05-19 Thread Matthew Ong

On 5/19/2011 2:32 AM, Jacob Carlborg wrote:

On 2011-05-18 20:05, Jonathan M Davis wrote:

On 5/18/2011 10:46 PM, Steven Schveighoffer wrote:

but you can do a string mixin to define the entire class. This is not
an easy thing to do, because you'd have to write the entire class as a
string of text.


Thanks for the attempt and sample code.

Seen that script import somewhere before. Perhaps others would like to
help.

Does mixin generate the same binary code as #define as inline code,which
meant that same binary is repeated everywhere that macro is used?

Or does it make a linked to the in a centralized locations that allow
binary sharing when it is the same typed T??

Do you have any idea? because the results is in dll/exe I cannot really
tell. But someone that knows how the compiler works should be able to.


First off, template mixins and string mixins are different beasts. In one
case, you're mixing in a template. In the other, you're mixing in
strings of
code. Template mixins must be valid code even without being mixed in.
String
mixins have to result in valid code, but they're strings so they can hold
anything. Both types of mixins, however, have to be explicitly mixed
in (as
opposed to the textual replacement that #defines do). In the case of
template
mixins, you're essentially copying and pasting code. In the case of
string
mixins, you're creating strings that are the code, so it's pretty much
just
like if you typed the code in there yourself except that the compiler is
putting it in there for you instead, allowing you to use functions to
generate
code and save you from having to type it all. There is no linking
involved in
mixins. It's not shared. You're generating code and inserting it where
you
used the mixin statement.

- Jonathan M Davis


Template mixins are not exactly like copy and paste code.

* You can mixin the same template, at the same location, twice, taking
different parameters

* Mixed in methods doesn't overload on existing methods in the scope
where the mixin is used

I think all this is due to mixins being mixed-in in it's own scope.


Hi Jacob,

The last message confused me. Please clarify.
>not exactly like copy and paste code.
Ok...So, does it meant that the compiler share some sort of binary?

In java using template, the same LinkedList binary is shared for both 
String class type and also Integer class type.


LinkedList list=new LinkedList();
LinkedList list=new LinkedList();

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


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

mixin template does seemed to be better than #define (uncheck by 
compiler directly) it can be any text. M4 is a tool exactly that purpose.




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



Re: Can someone explain how mixin is implemented?

2011-05-19 Thread Matthew Ong

On 5/19/2011 9:18 PM, Matthew Ong wrote:

On 5/19/2011 1:23 AM, Jesse Phillips wrote:

Matthew Ong Wrote:


Perhaps I am missing something here. How can class level definition be
part of the mixin?

Does mixin generate the same binary code as #define as inline code,which
meant that same binary is repeated everywhere that macro is used?

Or does it make a linked to the in a centralized locations that allow
binary sharing when it is the same typed T??


I can see what you're trying for and it looks like you'll need string
mixins to make it happen.

Mixing is similar to #define in that it does string substitution, but
it is unlike #define in that valid D is required declaration and call.
You'll have to modify this with string mixins (I'm surprised it
compiles excluding the non-existence of ClassB):

mixin template AType(alias T, U, alias V){class T : ClassC {
private:
U value;
public:
this(){}
void print(){}
mixin V;
}
}

class ClassC {}

mixin template btype() {
void someFunction() {};
}

mixin AType!("ClassB", string, btype);

void main() {
ClassC r = new ClassB();
}



Hi Jesse,
That is cool. Useful example like this should be within the
documentation also. That helped me a lot. Now, I do not have to be
concerned that the class level mixin usage class missed out the
inheritance and also the implementation.

This pattern is very useful for flattening the Object inheritance tree.
D is cool!!!


Hi jesse,

I obtain error from: ClassC r = new ClassB();

src\main.d(27): Error: undefined identifier ClassB, did you mean class 
ClassC?

src\main.d(27): Error: ClassB is used as a type

Somehow this information is not known to the compiler
mixin AType!("ClassB", string, btype);

Please help.

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



Re: Can someone explain how mixin is implemented?

2011-05-19 Thread Matthew Ong

On 5/19/2011 1:23 AM, Jesse Phillips wrote:

Matthew Ong Wrote:


Perhaps I am missing something here. How can class level definition be
part of the mixin?

Does mixin generate the same binary code as #define as inline code,which
meant that same binary is repeated everywhere that macro is used?

Or does it make a linked to the in a centralized locations that allow
binary sharing when it is the same typed T??


I can see what you're trying for and it looks like you'll need string mixins to 
make it happen.

Mixing is similar to #define in that it does string substitution, but it is 
unlike #define in that valid D is required declaration and call. You'll have to 
modify this with string  mixins (I'm surprised it compiles excluding the 
non-existence of ClassB):

mixin template AType(alias T, U, alias V){class T : ClassC {
private:
 U value;
public:
 this(){}
 void print(){}
 mixin V;
}
}

class ClassC {}

mixin template btype() {
 void someFunction() {};
}

mixin AType!("ClassB", string, btype);

void main() {
 ClassC r = new ClassB();
}



Hi Jesse,
 That is cool. Useful example like this should be within the 
documentation also. That helped me a lot. Now, I do not have to be 
concerned that the class level mixin usage class missed out the 
inheritance and also the implementation.


This pattern is very useful for flattening the Object inheritance tree.
D is cool!!!

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



Re: Can someone explain how mixin is implemented?

2011-05-18 Thread Matthew Ong

On 5/18/2011 10:46 PM, Steven Schveighoffer wrote:

but you can do a string mixin to define the entire class.  This is not
an easy thing to do, because you'd have to write the entire class as a
string of text.

Thanks for the attempt and sample code.

Seen that script import somewhere before. Perhaps others would like to help.

Does mixin generate the same binary code as #define as inline code,which 
meant that same binary is repeated everywhere that macro is used?


Or does it make a linked to the in a centralized locations that allow 
binary sharing when it is the same typed T??


Do you have any idea? because the results is in dll/exe I cannot really 
tell. But someone that knows how the compiler works should be able to.


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



Re: How to break module into multiple file.

2011-05-18 Thread Matthew Ong

On 5/13/2011 3:51 PM, Alexander wrote:

On 13.05.2011 00:59, Jonathan M Davis wrote:


Still, I wouldn't have though that dashes would have been a big enough deal to 
really care.


   I didn't say that this is a "big deal", just "inconvenience".

   There are many minor things which are not a big deal, but make life a bit 
less convenient - and this is the exact reason why we have so many programming 
languages, libraries etc :)

/Alexander
I agreed with what alexander is voicing out. How about the process 
within a team development. That current D layout seem to limit that one 
file to a single developer. Instead of multiple class multiple developer 
within the same module.

Using the example:
HashMap & Unit tested implemented by matthew
LinkedList & Unit tested implemented by john
but the same module is handled by Jonathan for other classes?

Perhaps some one can show how this is done with Subversion / CVS for 
this team?


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



Can someone explain how mixin is implemented?

2011-05-18 Thread Matthew Ong

Hi,
From what I can see mixin in D is used in place of #define in 
C++(cool!!!). However, I do have a few question.


mixin with template does address some of this issue I supposed. That 
does allow me to define up to level of content of a class but is not 
class itself.


mixin template AType(T){ // but does not seems to allow me to inherit 
ClassC this level.

private:
   T value;
public:
   this(){...}
   void print(){...}
}

class ClassB : ClassC{ // ClassC Inheritance/Interface must only be done 
at this level?

   mixin AType!(string); // content
}

Perhaps I am missing something here. How can class level definition be 
part of the mixin?


Does mixin generate the same binary code as #define as inline code,which 
meant that same binary is repeated everywhere that macro is used?


Or does it make a linked to the in a centralized locations that allow 
binary sharing when it is the same typed T??



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



Re: How to break module into multiple file.

2011-05-12 Thread Matthew Ong
Hi Adam,

Ok. Just to be very clear here. Please help to validate.

>Common interfaces for both HashMap, LinkedList and hashlist.

>But they should be all be in different source file(HashMap.d, >LinkedList.d,
HashList.d)..

To have import for:

module CornerCube.Collections

class HashMap{...}

I would have to layout as:

MyLib/Collection.d << HashMap, LinkedList, HashList within this file
The single Collection.d works for me but hard to maintain manually.

For this one I use import MyLib.Collection;

or

MyLib/Collections/HashMap.d << Single class file. but module Corner
CornerCube/Collection/LinkedList.d
CornerCube/Collection/HashList.d

This one I have error.
import MyLib.Collection;
This also I have error.
import MyLib.Collection.LinkedList;
import MyLib.Collection.HashList;
// Some sort of recursive import...


How do I import them within the calling class?




Re: How To Dynamic Web Rendering?

2011-05-12 Thread Matthew Ong
Hi Adam,

Thanks again for the sharp pointed answer.
> What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or
> some sort of dynamic web base development?

>I use D for web work by using the standard CGI interface and >sometimes
>an embedded http server. It's the best thing I've ever used.
Could you share how or show an URL that provide sample code to do that in D?


> How to also code digitally sign the DLL  that was compiled in D?
The same way you sign any other dll/exe.
So we use external tool to do that and not a build in one??
In java, we use jarsigner with some keygen.

Please bear in mind I am new to D.



How to break module into multiple file.

2011-05-12 Thread Matthew Ong
Hi,

According to:
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=135947

And also source code within dmd2/src
It seems that there is only one file per module.

Is module similar to a single java package and namespace in VC++/C#?

If yes, most name spaced programming language allow breaking of single module
into multiple
file to store various logically linked class and separate them when they are 
not.

Like module Collection may have:
Common interfaces for both HashMap, LinkedList and hashlist.

But they should be all be in different source file(HashMap.d, LinkedList.d,
HashList.d) but
logically within the same module collection.(Directory)
How do I do that within D? what is the directory layout of the project?

Matthew Ong


How to search news group?

2011-05-12 Thread Matthew Ong
Hi D Forum Admin,

I am using the webbase interface for the forum.
How to do forum text search instead of browsing over them one by one?

Matthew Ong



How To Dynamic Web Rendering?

2011-05-12 Thread Matthew Ong
Hi,

What is the counterpart in D for replacing JSP/ASP/JRuby on Rail or some sort
of dynamic web base development?

How to compile a D code into dll to be used by apache or MS IIS?

How to also code digitally sign the DLL  that was compiled in D?

Matthew Ong