Static method conflicts with non-static method?
so
so at so.so
Fri Apr 27 06:15:31 PDT 2012
On Friday, 27 April 2012 at 12:35:53 UTC, Steven Schveighoffer
wrote:
> Huh? The main reason of confusion is that the static method is
> named in such a way that it looks like an instance method. So
> we prevent that, unless the author of the class (who is
> deciding the name of the function) deems it should be called on
> instances
>
> example:
>
> struct File
> {
> static File open(string name) {...} // factory method
> this(string name);
> }
>
> File f = File("hello");
>
> f.open("world"); // oops! Just opened file world and threw it
> away
> f = File.open("world");// better!
With your proposal you can still do "f.open("world");" and get
the same result if the author provided alias. You are trying to
solve another problem, that the author should better state if
this is intended. The problem i see is user assumming author is a
smart guy. But at the end he finds out the author is as dumb as
himself {he should have RTFM :)}
> I challenge you to name File.open some way where it *wouldn't*
> be confusing when called on an instance :)
>
> -Steve
Easy! Don't call on an instance! openFile() out of the struct.
I always add "make_" before any static function, otherwise static
methods should be precise as
http://forum.dlang.org/post/araqkvvgyspzmdecxqxi@forum.dlang.org
More information about the Digitalmars-d
mailing list