| Thread overview | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 03, 2009 Many questions | ||||
|---|---|---|---|---|
| ||||
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... - Why there is no ranged foreach in D1? - Why there is no pure keyword in D1? - Why cent (128 bit integer) is not implemented? - 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? - Why methods are virtual by default? if i export a class in a DLL, all methods are threated as virtual? - Why enum uses int by default? why not ubyte? or the integral type that matches best with the min and max? - Why exists typedef and alias? in modern languages like C#, i can not see these things (these are confusing)... - Assosiative array: why stores the keys? why not the hashes? - 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++... - 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? - Why there is no XML module in Phobos for D1? - Is there any standard API like the .NET base classes for D? - Why the overrided method does not inherit the default values for arguments? Thanks in advance | ||||
May 03, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal | 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 | |||
May 03, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal | 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 | |||
May 03, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal | == Quote from Fractal (d294934@bsnow.net)'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 | |||
May 03, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal | Hello, and welcome Fractal. I can give you some answers; other people will fill the missing ones. I can see you come from C#. D isn't C#, and not everything C# does differently from D is an mistake of the D design. Sometimes it's just a different way to do things, sometimes it's a design that is more fit for the other features of D, some times it's a design error of D, and sometimes it's a design error of C#. >- Why i cant use many files with the same module name?< Because that's messy. >I want to use modules like .NET or C++ namespaces and the file has 10K lines and finding a line takes many time...< My serious (wise) advice is to use smaller files. >- Why there is no ranged foreach in D1? - Why there is no pure keyword in D1?< Because D is developed mostly by a person (Walter), and such person can't keep two (three) compilers updated. And maybe because Walter wants people to slowly leave D1 behind and use D2. >- Why cent (128 bit integer) is not implemented?< Probably because not enough people have asked for it, because it's not easy to find purposes for them, and because Don (and you) have not implemented them yet. LDC compiler already has a partial support for them, probably once LLVM 2.6 comes out they may become usable. >- Why methods are virtual by default?< To simplify the life of the programmer, I presume (see Java). And because smart compilers are supposed to magically devirtualize them. >- Why enum uses int by default? why not ubyte?< Probably because int/uint are the faster types to manage by the CPU, because today memory is cheap, and because even if you use an ubyte often you don't save memory anyway because the following variables in the stack/heap may be aligned to 4 bytes aniway, so you often end with 3 bytes of padding after it. >- Why exists typedef and alias?< Alias is very useful, to "change" name of member functions, to define different names and types, etc. You can see why typedef is useful if you come from Pascal-like languages, and when you don't use much Object oriented programming. For example you may have some functions that take an array, with a typedef you can be sure it's the right kind of array and not an array with the same number of dimensions and the same base type. >in modern languages like C#, i can not see these things (these are confusing)...< Typedef isn't confusing. In the universe there are things that C# doesn't have yet. D is modern but has typedef. >- Assosiative array: why stores the keys? why not the hashes?< Where do you want to keep the keys? >- Why no multiple inheritace?< Probably because Walter thinks it's a complex feature that often you don't really need. D tries to be less quite complex than C++, even if this reduces the power of D a bit. >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++...< I don't understand you much. Have you tried a "template mixin"? >is there any way to make a class like an opaque pointer? (but with the same sintax of a common class)< I don't think so. >- Why there is no XML module in Phobos for D1?< Because Walter has not found the time to do it. Take a look at Phobos. >- Is there any standard API like the .NET base classes for D?< Nope. Not in Phobos. Maybe something vaguely similar may be created in the future. >- Why the overrided method does not inherit the default values for arguments?< I don't know. Maybe Walter has not thought about this yet. Bye, bearophile | |||
May 04, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | > interface I > { > void shine(); > } > > class C : I > { > final void shine() { } > } > > void main() > { > C c = new C(); > I i = c; I didn't know an interface could hold the data of an class or am I seeing this wrong? > > i.shine(); // Virtual > c.shine(); // Direct > } | |||
May 04, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal | Hello again... Thanks for the quick responses! and sorry... if my english is very bad :) C#: No, i dont have been used C# for anything. But i like the .NET framework structure. How ever not at all (it also uses interfaces). The namespaces: i used them with C++, and the idea of separation between the uses of types, makes a very good layout. Because some namespaces requires more types, always i write each class in separate files. D simply breaks it, making a big amount of lines for imports. Automatic contructor: for example the exceptions. Exception is a simple class that takes one argument. When making others exceptions, it is not necessary write the constructor (if not takes other args) Force super call: if a base class uses a method for releasing system resources, and in a inherited class, i "forget", (or intencionally?), write the super.release() or something when overriding the method, many problems will occour... Templates: i dont use templates or mixins. they really confuses me and i think so that they only should be used for "array classes" or something similar. Associative arrays: yes, i can make my own implementation, but also the language provides it natively, and with optimizations... Foreach ranged: it cannot be added to D1? it simplies the life, and not breaks any existing code cent: just for hashing... in C++ i can see the type __int128 (using Visual Studio) Tango and Phobos: Tango is good, but the File class makes more problems than it solves. And i dont like the Phobos design, but I really need the XML... just writing other API? And.. thanks again | |||
May 04, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal |
> Templates: i dont use templates or mixins. they really confuses me and i think so that they only should be used for "array classes" or something similar.
>
Do you mean you don't understand the concept of mixins or that it makes
reading the code more difficult?
If it is the first then I don't really get it: you sound like somebody who
gets a lot of things.
mixins are just code in string form, right?
| |||
May 04, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Saaa | Saaa Wrote:
>
> > Templates: i dont use templates or mixins. they really confuses me and i think so that they only should be used for "array classes" or something similar.
> >
> Do you mean you don't understand the concept of mixins or that it makes
> reading the code more difficult?
> If it is the first then I don't really get it: you sound like somebody who
> gets a lot of things.
> mixins are just code in string form, right?
>
>
It is the second. Mixins for me, makes difficult to read the code. but I have to admit that they are useful.
| |||
May 04, 2009 Re: Many questions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Fractal |
>
>>
>> > Templates: i dont use templates or mixins. they really confuses me and
>> > i
>> > think so that they only should be used for "array classes" or something
>> > similar.
>> >
>> Do you mean you don't understand the concept of mixins or that it makes
>> reading the code more difficult?
>> If it is the first then I don't really get it: you sound like somebody
>> who
>> gets a lot of things.
>> mixins are just code in string form, right?
>>
>>
>
> It is the second. Mixins for me, makes difficult to read the code. but I have to admit that they are useful.
Thats what you get with a systems programming language ; ) But I understand where you are coming from.
Please ask as many questions as you want. They teach me as well :)
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply