Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 13, 2013 static vs non-static | ||||
---|---|---|---|---|
| ||||
Hi! Sorry,if it already was discussed,but import std.stdio; struct Foo { static void bar() { writeln("static"); } void bar() { writeln("non-static"); } } int main() { Foo gun; gun.bar();//fails here } Is it all right,that compiler dosn't prefer non-static function in ths case? |
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Sunday, 13 January 2013 at 15:58:56 UTC, Zhenya wrote:
> Hi!
> Sorry,if it already was discussed,but
>
> import std.stdio;
>
> struct Foo
> {
> static void bar()
> {
> writeln("static");
> }
> void bar()
> {
> writeln("non-static");
> }
> }
>
> int main()
> {
> Foo gun;
> gun.bar();//fails here
> }
>
> Is it all right,that compiler dosn't prefer non-static function in ths case?
Main should be void in this case.
Yes, it is a problem - dmd allows to call static functions on instance. When both match, it issues ambiguity error.
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Sunday, 13 January 2013 at 16:18:36 UTC, Maxim Fomin wrote:
> On Sunday, 13 January 2013 at 15:58:56 UTC, Zhenya wrote:
>> Hi!
>> Sorry,if it already was discussed,but
>>
>> import std.stdio;
>>
>> struct Foo
>> {
>> static void bar()
>> {
>> writeln("static");
>> }
>> void bar()
>> {
>> writeln("non-static");
>> }
>> }
>>
>> int main()
>> {
>> Foo gun;
>> gun.bar();//fails here
>> }
>>
>> Is it all right,that compiler dosn't prefer non-static function in ths case?
>
> Main should be void in this case.
>
> Yes, it is a problem - dmd allows to call static functions on instance. When both match, it issues ambiguity error.
Hmmm...So it will remain as it is?
It hurts me a little bit(
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | Maxim Fomin:
> dmd allows to call static functions on instance.
I think that's a D design mistake (and I think Jonathan Davis agrees with me), but Walter prefers the current behavour.
Bye,
bearophile
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Sunday, 13 January 2013 at 16:39:22 UTC, bearophile wrote:
> Maxim Fomin:
>
>> dmd allows to call static functions on instance.
>
> I think that's a D design mistake (and I think Jonathan Davis agrees with me), but Walter prefers the current behavour.
>
> Bye,
> bearophile
Maybe you could suggest some workaround?
for example I tried to use global function,but
in that case it never will be executed...
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Sunday, 13 January 2013 at 16:39:22 UTC, bearophile wrote:
> Maxim Fomin:
>
>> dmd allows to call static functions on instance.
>
> I think that's a D design mistake (and I think Jonathan Davis agrees with me), but Walter prefers the current behavour.
>
> Bye,
> bearophile
Then I agree with both of you, however I found this issue not very dramatical (comparing with other problems), probably because I haven't hit some problems with it.
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Sunday, 13 January 2013 at 17:04:21 UTC, Maxim Fomin wrote:
> On Sunday, 13 January 2013 at 16:39:22 UTC, bearophile wrote:
>> Maxim Fomin:
>>
>>> dmd allows to call static functions on instance.
>>
>> I think that's a D design mistake (and I think Jonathan Davis agrees with me), but Walter prefers the current behavour.
>>
>> Bye,
>> bearophile
>
> Then I agree with both of you, however I found this issue not very dramatical (comparing with other problems), probably because I haven't hit some problems with it.
I just was writting something like n-dimensional dispatcher,described in Andrei's Modern C++ design,and I needed to write classinfo analog by hands.
|
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | On Sunday, 13 January 2013 at 16:23:27 UTC, Zhenya wrote: > On Sunday, 13 January 2013 at 16:18:36 UTC, Maxim Fomin wrote: >> Yes, it is a problem - dmd allows to call static functions on instance. When both match, it issues ambiguity error. > Hmmm...So it will remain as it is? > It hurts me a little bit( Frankly speaking I do not know - I keep an eye on D project for some period of time and remember how some features I considered stable were easily changed. If Walter is for current behavior - than it will remain as it is (unless Walter is overpersuaded). What I would do is not writing code which is looking for problems. BTW, take look at this thread http://forum.dlang.org/thread/pkodcsxwwehumhtkrlty@forum.dlang.org (posts 1-3). |
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhenya | Definitely this is a bad design. Even in PHP you can't call static functions from class instance. :-) Having two functions with the same name and argument list within one class is a bad idea too. |
January 13, 2013 Re: static vs non-static | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Sunday, 13 January 2013 at 17:17:54 UTC, Maxim Fomin wrote:
> On Sunday, 13 January 2013 at 16:23:27 UTC, Zhenya wrote:
>> On Sunday, 13 January 2013 at 16:18:36 UTC, Maxim Fomin wrote:
>>> Yes, it is a problem - dmd allows to call static functions on instance. When both match, it issues ambiguity error.
>> Hmmm...So it will remain as it is?
>> It hurts me a little bit(
>
> Frankly speaking I do not know - I keep an eye on D project for some period of time and remember how some features I considered stable were easily changed. If Walter is for current behavior - than it will remain as it is (unless Walter is overpersuaded).
>
> What I would do is not writing code which is looking for problems.
>
> BTW, take look at this thread http://forum.dlang.org/thread/pkodcsxwwehumhtkrlty@forum.dlang.org (posts 1-3).
Thank you.
|
Copyright © 1999-2021 by the D Language Foundation