digitalmars.D - Precedence of 'new' vs '.'
- Frank Benoit (5/5) May 05 2009 In Java one can write:
- BCS (2/12) May 05 2009 vote++
- Robert Fraser (2/18) May 05 2009 me too... Bugzilla, anyone?
- Frank Benoit (2/3) May 05 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2945
- Nick Sabalausky (11/16) May 05 2009 I'm torn on this.
- Derek Parnell (8/17) May 05 2009 So presumably if it was changed to behave as Java, to get the current
- Jarrett Billingsley (3/6) May 05 2009 Except that currently has no meaning, since you can't return a type
- Ary Borenszweig (11/20) May 05 2009 I think it's because the (already hated by many, including myself)
- Steven Schveighoffer (14/30) May 06 2009 If properties are every properly established, I hope the ability to call...
- Eldar Insafutdinov (9/18) May 06 2009 Related problem:
- Nick Sabalausky (4/12) May 06 2009 Unless I misunderstand your point, that's already in bugzilla:
In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?
May 05 2009
Reply to Frank,In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?vote++
May 05 2009
BCS wrote:Reply to Frank,me too... Bugzilla, anyone?In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?vote++
May 05 2009
Robert Fraser schrieb:me too... Bugzilla, anyone?http://d.puremagic.com/issues/show_bug.cgi?id=2945
May 05 2009
"Frank Benoit" <keinfarbton googlemail.com> wrote in message news:gtqf6c$8ma$1 digitalmars.com...In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?I'm torn on this. On one hand, I'm uncomfortable with having an operator that requires whitespaces bind tighter than an operator that isn't typically used with whitespace. To me, "new MyClass().run();" just *looks* like run() returns a type and you're trying to instantiate *that* type (with a default constructor). But on the other hand, I can certainly see the practiclity of the Java version and I've frequently had reason to use "(new MyClass()).run();" in my own code.
May 05 2009
On Wed, 06 May 2009 00:39:12 +0200, Frank Benoit wrote:In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?So presumably if it was changed to behave as Java, to get the current functionality one would need to write ... new (MyClass().run()); -- Derek Parnell Melbourne, Australia skype: derek.j.parnell
May 05 2009
On Tue, May 5, 2009 at 8:49 PM, Derek Parnell <derek psych.ward> wrote:So presumably if it was changed to behave as Java, to get the current functionality one would need to write ... new (MyClass().run());Except that currently has no meaning, since you can't return a type from a function :P
May 05 2009
Frank Benoit escribió:In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?I think it's because the (already hated by many, including myself) ability to invoke a function (or a constructor) without parenthesis. So: new MyClass.run and new MyClass().run should be the same, right? But in the first case MyClass could be a package name and you are constructing a new "MyClass.run" instance. You could make them behave differently, but some would say it's not consistent, etc.
May 05 2009
On Tue, 05 May 2009 21:43:54 -0400, Ary Borenszweig <ary esperanto.org.ar> wrote:Frank Benoit escribió:If properties are every properly established, I hope the ability to call default constructors without having parens does not go away. It's different than a property function call. I would say it's ok to make them behave differently. As others have said, we already have instances where you have to use parens to delineate where you are calling a function versus accessing a member. For example, the (admittedly seldom used) chaining call of Stdout in Tango, if you want to insert a new line it's: Stdout("hi")(4).newline()("hi"); Without the extra parens, it looks like you're trying to call newline with the argument "hi". -SteveIn Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?I think it's because the (already hated by many, including myself) ability to invoke a function (or a constructor) without parenthesis. So: new MyClass.run and new MyClass().run should be the same, right? But in the first case MyClass could be a package name and you are constructing a new "MyClass.run" instance. You could make them behave differently, but some would say it's not consistent, etc.
May 06 2009
Frank Benoit Wrote:In Java one can write: new MyClass().run(); in D this does not compile, parenthesis are needed. (new MyClass()).run(); But why is the D language designed like that?Related problem: string str = "qwe rty uio"; string[] arr = str.split(" "); // works class A { string foo() { return "qwe rty uio"; } } A a = new A; a.foo.split(" "); // doesn't work
May 06 2009
"Eldar Insafutdinov" <e.insafutdinov gmail.com> wrote in message news:gtrooc$2ff9$1 digitalmars.com...Related problem: string str = "qwe rty uio"; string[] arr = str.split(" "); // works class A { string foo() { return "qwe rty uio"; } } A a = new A; a.foo.split(" "); // doesn't workUnless I misunderstand your point, that's already in bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=2883
May 06 2009