Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 18, 2004 inheritance syntax | ||||
---|---|---|---|---|
| ||||
Hello, I'm wondering why D doesn't use the Java-style syntax for class inheritance (extends, implements), because I thought D's purpose was to have the clearest possible syntax. In its current state, it seems to me it's not possible to determine visually the type of inheritance, eg.: class Y: A, B, C, D { } is it immediatly possible to say which of A, B, C or D are interfaces or classes ? bye, Marc |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc | Marc wrote: >Hello, > >I'm wondering why D doesn't use the Java-style syntax for class inheritance >(extends, implements), because I thought D's purpose was to have the clearest >possible syntax. >In its current state, it seems to me it's not possible to determine visually the >type of inheritance, eg.: > >class Y: A, B, C, D >{ >} > >is it immediatly possible to say which of A, B, C or D are interfaces or classes >? > >bye, >Marc > > > D copies a lot of syntax from C++ which makes it easy for people who use the worlds most popular language to learn D. -- -Anderson: http://badmama.com.au/~anderson/ |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | IMHO, the reason you're giving me is not satisfying. D is supposed to be a language that solves the flaws of C++. That was successfully done with templates, and you won't say that the new syntax is familiar to C++ developers ;) I think the ':' inheritance syntax is one of C++ flaws. I'm a C++ supporter, but I find that the words 'extends' and 'implements' are really expressive and meaningful (and leave no place for contextual interpretation). So, if i follow your argument, why not having D support both syntaxes, so C++ and Java developers will both feel at ease with it ? In article <c8clja$2dn$1@digitaldaemon.com>, J Anderson says... > >Marc wrote: > >>Hello, >> >>I'm wondering why D doesn't use the Java-style syntax for class inheritance >>(extends, implements), because I thought D's purpose was to have the clearest >>possible syntax. >>In its current state, it seems to me it's not possible to determine visually the >>type of inheritance, eg.: >> >>class Y: A, B, C, D >>{ >>} >> >>is it immediatly possible to say which of A, B, C or D are interfaces or classes ? >> >>bye, >>Marc >> >> >> >D copies a lot of syntax from C++ which makes it easy for people who use the worlds most popular language to learn D. > >-- >-Anderson: http://badmama.com.au/~anderson/ |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to marc.noirotREM | marc.noirotREM@OVEfleximage.fr wrote: > So, if i follow your argument, why not having D support both syntaxes, so C++ > and Java developers will both feel at ease with it ? > > Obviously you can't have to many alias for things in languages, it makes the language to broad (language design 1.0 -> unit). You have to pick one direction and stick with it. Why not also make blocks { } begin and end? -- -Anderson: http://badmama.com.au/~anderson/ |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | >Obviously you can't have to many alias for things in languages, it makes the language to broad (language design 1.0 -> unit). You have to pick one direction and stick with it. Why not also make blocks { } begin and end?
>
Of course, i agree with you, i was actually being half-sarcastic.
But well, let's elude that point...
I think ':' is acceptable in C++ because it doesn't have the builtin notion of
interface.
But like in Java, D's class inheritance and interface implementation are two
different notions, so why writing them as if they were the same thing ?
If we make abstraction of the fact that D wants to stick with C++ syntax, what
is the best for someone trying to learn a language from scratch ?
A perlish symbol like ':' expressing 2 notions ? Or two words like 'extends' and
'implements' that leave no doubt about the context ?
Thanks for your patience in answering my irritating questions :P Marc
|
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to marc.noirot | marc.noirot@REMOVEfleximage.fr wrote: >>Obviously you can't have to many alias for things in languages, it makes the language to broad (language design 1.0 -> unit). You have to pick one direction and stick with it. Why not also make blocks { } begin and end? >> >> >> > >Of course, i agree with you, i was actually being half-sarcastic. > >But well, let's elude that point... > >I think ':' is acceptable in C++ because it doesn't have the builtin notion of >interface. >But like in Java, D's class inheritance and interface implementation are two >different notions, so why writing them as if they were the same thing ? > > Often you only want to implement one interface/class and users don't care if its a class or interface. I believe it helps to keep things like this generic. You don't need to search the docs to find out if something is an interface or class. If you need to use more then one interface, then you can search the docs, if nessary. Furthermore if the developer wishes to change an interface to a class (or visa versa), they won't have maintance problems in D. If you really want this documentation you can put a comment in. >If we make abstraction of the fact that D wants to stick with C++ syntax, what >is the best for someone trying to learn a language from scratch ? >A perlish symbol like ':' expressing 2 notions ? Or two words like 'extends' and >'implements' that leave no doubt about the context ? > >Thanks for your patience in answering my irritating questions :P >Marc > > No worries. -- -Anderson: http://badmama.com.au/~anderson/ |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | ok, what about this ? : //interclace.d import std.c.stdio; //* version=1; //*/ version (1) { interface A { char [] toString(); } } else { class A { char [] toString() { return "3"; } } } /* if version = 1, super.toString == Object.toString, else super.toString == A.toString */ class B: A { char [] toString() { return super.toString() ~ "1"; } } void main() { B b = new B; printf("B: %s\n", cast(char *)b.toString()); // what does it print ? } //EOF the output of b.toString() is not 'really' predictable if version = 1 (Object.toString seems to print "Object", but is it implementation dependant ?)although both versions are valid and compile fine. weirdness, weirdnesss, doesn't it look like a potential source of bugs that could be avoided with explicit "implements" or "extends" ? |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc | Marc wrote: >ok, what about this ? : > >//interclace.d >import std.c.stdio; > >//* >version=1; >//*/ > >version (1) { >interface A { >char [] toString(); >} >} >else { >class A { >char [] toString() { >return "3"; >} >} >} > >/* if version = 1, super.toString == Object.toString, >else super.toString == A.toString */ >class B: A { >char [] toString() { >return super.toString() ~ "1"; >} >} > >void main() { >B b = new B; >printf("B: %s\n", cast(char *)b.toString()); // what does it print ? >} > >//EOF > >the output of b.toString() is not 'really' predictable if version = 1 >(Object.toString seems to print "Object", but is it implementation dependant >?)although both versions are valid and compile fine. >weirdness, weirdnesss, doesn't it look like a potential source of bugs that >could be avoided with explicit "implements" or "extends" ? > > > > This is one reason I like D's form of interfaces. Later in a maintanace cycle it may be decided that interface A is better off as an abstract class (or whatever). If you had implements and extends you'd need too go to every one of your clients code and modify it to work. Besides you can easily produce the error message you want by adding a stub constructor and calling super. -- -Anderson: http://badmama.com.au/~anderson/ |
May 18, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to marc.noirotREM | marc.noirotREM@OVEfleximage.fr wrote:
> IMHO, the reason you're giving me is not satisfying.
> D is supposed to be a language that solves the flaws of C++.
> That was successfully done with templates, and you won't say that the new syntax
> is familiar to C++ developers ;)
> I think the ':' inheritance syntax is one of C++ flaws. I'm a C++ supporter, but
> I find that the words 'extends' and 'implements' are really expressive and
> meaningful (and leave no place for contextual interpretation).
> So, if i follow your argument, why not having D support both syntaxes, so C++
> and Java developers will both feel at ease with it ?
It is not a flaw at all, merely a different syntax, as it does not effect *what* can be expressed in D, merely how it is expressed.
-- andy
|
May 19, 2004 Re: inheritance syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc | Marc wrote:
> Hello,
>
> I'm wondering why D doesn't use the Java-style syntax for class inheritance
> (extends, implements), because I thought D's purpose was to have the clearest
> possible syntax.
> In its current state, it seems to me it's not possible to determine visually the
> type of inheritance, eg.:
>
> class Y: A, B, C, D
> {
> }
>
> is it immediatly possible to say which of A, B, C or D are interfaces or classes
> ?
>
> bye,
> Marc
>
>
Hi.
How about writing like this?
class Foo : SuperClass
, InterfaceOne
, InterfaceTwo
, InterfaceThree
{
}
|
Copyright © 1999-2021 by the D Language Foundation