Many questions

Robert Fraser fraserofthenight at gmail.com
Sun May 3 16:39:33 PDT 2009


Fractal wrote:
 > - 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...

Errr... no offense, but that kinda sounds like a bad design...

> - Why there is no ranged foreach in D1?

It was introduced after D2 was started... really, this is such a benign 
(and useful!) feature I think it should be backported, but whatever.

> - Why there is no pure keyword in D1?

Pure requires immutable (constant) storage for guarantees. If you want 
const and pure, you should be using D2.

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

What's your use case? I honestly can't think of any time I'd prefer cent 
over an actual BigInteger class.

> - 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 some template/mixin magic to do it, probably. I wouldn't 
mind having this in the core language, but... eh...

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

It reduces unexpected behavior in the common case. Exporting D classes 
in a DLL... in a lot of cases it won't work (DLLs have issues); I'd 
recommend DDL.

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

Not sure. FWIW, int is the same speed or faster than ubyte/ushort/etc. 
on 32-bit processors, so it really only matters for packed structs.

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

IMO, they're very useful, especially for backwards compatibility or long 
template names.

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

So you can enumerate through the keys/make a set type. If you want a 
hash-only hash, you can make one pretty easily.

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

MI has issues, especially with data layout. Use a mixin to share the 
code between classes:

template FooImpl()
{
	void foo() { ... }
}

class A : B
{
	mixin FooImpl!()
}

class C : D
{
	mixin FooImpl!()
}

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

I'm not sure what you mean. If you mark an overridden method as "final" 
any calls to it from something of the class type will be direct.

interface I
{
	void shine();
}

class C : I
{
	final void shine() { }
}

void main()
{
	C c = new C();
	I i = c;
	
	i.shine(); // Virtual
	c.shine(); // Direct
}

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

No.

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

It just wasn't implemented before D2 came out. Honestly, I'd recommend 
either Tango+D1 or Phobos+D2... Phobos+D1 is the least supported of the 
three, and D1 Phobos is pretty skimpy.

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

Um... the classes in Phobos or the classes in Tango? (The Tango ones are 
more .NET-like).

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

No idea, but that would be useful.

> Thanks in advance



More information about the Digitalmars-d mailing list