Many questions

dsimcha dsimcha at
Sun May 3 16:53:07 PDT 2009

== Quote from Fractal (d294934 at's article
> 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...

If I understand your question correctly, you can very easily simulate this with a
public import.  Put some of the code in a different module, and publicly import
that module in your main module.

> - Why there is no ranged foreach in D1?

D1 is supposed to be stable, and they were thought of after D1 was declared
stable.  D1 is supposed to receive bug fixes only, not changes to spec.

> - Why there is no pure keyword in D1?

Same reason as no ranged foreach.

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

It's just a low priority and noone's gotten around to it.  There aren't too many
use cases where 64 bits isn't big enough, but 128 is.

> - 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?

Would be nice.  I've thought of the same thing before, but never really brought it
up b/c it seemed like a relatively minor thing.

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

Methods are virtual by default because it avoids subtle bugs caused by not
declaring something virtual and then overriding it.  If you really want to avoid
the overhead of virtual methods, make the method final.  You won't be able to
override it, but if it's not virtual, you probably shouldn't anyhow.

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

I guess b/c the spec was created with 32-bit hardware in mind and int and uint are
fastest on 32-bit hardware.

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

typedef is strong, i.e. the following would not work:

typedef int INT;
INT foo;
int bar;
bar = foo;  // Would require a cast.

alias is weak, i.e. the above would work.  They're really two different concepts,
albeit in a subtle way.

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

1.  The hashes are also stored for speed.
2.  You need to know the key to resolve hash collisions and to iterate over the AA.

> - 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++...

This one is somewhat controversial, and I won't start a multiple inheritance holy
war.  However, I will suggest looking into template mixins and string mixins as a
possible substitute for many use cases of multiple inheritance.

> - 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)
> - When overriding a method: is possible force an inherited class to call the
base method?

Not any way I'm aware of.  This is something that might just have to be enforced
by convention.  Then again, you could check to make sure whatever the base method
is supposed to do has been done, using invariant() contracts.

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

Because the D1 version of Phobos just plain sucks, to be honest.  I highly
recommend against its use.  Phobos has improved by leaps and bounds for D2.  If
you use D1, you should use Tango.

> - Is there any standard API like the .NET base classes for D?
> - Why the overrided method does not inherit the default values for arguments?

Because this would require that the compiler have the full source code for the
base class when compiling the derived class.  Default arguments are compile time
syntactic sugar.  The only ways to do this would be to get rid of separate
compilation entirely, or to make default arguments a part of the interface.

> Thanks in advance

More information about the Digitalmars-d mailing list