Many questions

Daniel Keep daniel.keep.lists at gmail.com
Sun May 3 16:46:03 PDT 2009



Fractal wrote:
> Hello
> 
> After using the D1 language i have some questions about it:
> 
> - Why i cant use many files with the same module name? I want to use modules like .NET or C++ namespaces and the file has 10K lines and finding a line takes many time...

Because in D, the module name maps to a file.  If the file is too big,
break it up.  You can use mixins, aliases or even public imports to
combine modules together.

> - Why there is no ranged foreach in D1?

Because it's in D2.*

> - Why there is no pure keyword in D1?

Because it's in D2.*

> - Why cent (128 bit integer) is not implemented?

Because no one's given a convincing argument why Walter should spend
time implementing it yet.  I could be wrong, but I don't think there's
any CPU support for them, either.

> - If a base class constructor has some parameters, when 
> creating a class that extends that base, if there is no constructor, create it automatically with the same parameters as the base class, and
> call it. Is possible to add this capability to D?

You could do it in D2 with a mixin.

> - Why methods are virtual by default? if i export a class in a DLL, all methods are threated as virtual?

Because it's more useful.  If you want to make them non-virtual, declare
them final.  That said, speaking from personal (and recent) experience,
there's nothing more annoying than a class you want to subclass where
all the methods are final.

> - Why enum uses int by default? why not ubyte? or the integral type that matches best with the min and max?

Because ints are faster.  I am not an expert, but I believe that most
32-bit CPUs can move ints around with the same speed, if not faster,
than smaller types.  The smaller moves are implemented as big moves +
shifts and masks.

> - Why exists typedef and alias? in modern languages like C#, i can not see these things (these are confusing)...

Because D is a modern language and they are very useful.  Well, alias is
definitely very useful; typedef is good to have.

> - Assosiative array: why stores the keys? why not the hashes? 

Because hashes are non-unique and if you didn't, you could NEVER
guarantee you'd found the correct slot.  You should brush up on your
data structures.

> - Why no multiple inheritace? if i have a simple (3 lines function) code and i need share it between many classes, i use an interface, and implementing the function in all the classes grows the code potentially. Simply if a class member name collides, threat as error. No virtual classes like C++...

Because Walter feels that MI isn't worth it.  Ever tried to work out out
to construct a Python object with multiple base class trees?  It's
horrible.  Just use interfaces and mixins.

> - Hiding class implementation like Windows COM can be done with an interface. but it makes all methods virtual... is there any way to make a class like an opaque pointer? (but with the same sintax of a common class)

Because... oh damn, so much for that idea.  I'm honestly not sure what
you're asking here.  If it's an opaque pointer, how would you do
anything with it?

> - When overriding a method: is possible force an inherited class to call the base method?

And this is why methods are virtual by default.  If it's not virtual,
then no.

> - Why there is no XML module in Phobos for D1?

Because it's in D2.*

> - Is there any standard API like the .NET base classes for D?

That would be Phobos or Tango, depending on which you're using.

> - Why the overrided method does not inherit the default values for arguments?

It just doesn't.

> Thanks in advance

* "Because it's in D2": changes made to D2 are, in general, not ported
back to D1.  D1 is supposed to be "stable" in the sense that only bug
fixes and new features that don't impact any existing code are made.


  -- Daniel



More information about the Digitalmars-d mailing list