"Nick Sabalausky" <[email protected]> wrote in message news:[email protected]... > > "bearophile" <[email protected]> wrote in message > news:[email protected]... >> >> A bit later in the discussion div0 and Pelle M. have said/suggested that >> accessing static vars through an instance can be a bad thing, and it's >> better to allow the programmer to access them only through the >> class/struct name. >> >> Bye, >> bearophile > > I've always felt that the ability to access static members through an > instance was just a bad idea in general, and this seems to add another > reason not to allow it. >
The one possible exception I can think of (and I'm not even sure if it's applicable to D or not) is if you're passed an instance of something and want to call a static member of it polymorphically. Without polymorphism you can just do "typeof(instance).staticFunc()", but I'm not sure offhand whether or not there's a way to do that polymorphically (or if static members can even be polymorphic). However, I think that if people are calling static members through instances instead of types just to make the call polymorphic, then I'd consider that less of a reason to allow "instance.staticMember" and more of a reason to have some sort of polymorphic runtime equivilent to typeof() (Do we currently have such a thing that can suffice?).
