Free functions versus member functions
Jarrett Billingsley
kb3ctd2 at yahoo.com
Thu Oct 11 05:38:00 PDT 2007
"Chad J" <gamerChad at _spamIsBad_gmail.com> wrote in message
news:fel0ol$tnn$1 at digitalmars.com...
> It would be nice to be able to write stdio.writefln(), which wouldn't lose
> much since it is very unlikely that there will be a series of imports like
> so:
> std.stdio;
> somelib.stdio;
> somelib.subpackage.stdio;
> In above such cases, well, too bad. Someone trying to figure out where
> stdio.writefln came from will just have to look it up.
>
>
> I may have just conflated two things unfortunately: compulsory FQN vs.
> voluntary FQN is one, and the other is the notion of a partially qualified
> name (PQN?). Currently D modules are voluntary FQN, while structs/classes
> act as compulsory PQN.
>
You might already know about this, but D already has a way to force the use
of module-level FQNs and a way to rename modules when importing them:
static import foo; // all members have to be accessed as foo.*
import stdio1 = somelib.stdio;
import stdio2 = somelib.subpackage.stdio;
// Now you can access stdio1.* and stdio2.*
The only somewhat annoyting part about this is that you have to do something
_at import time_, something whith can't be enforced by the library that's
being imported. I think it might be nicer if you could, at the very least,
declare a module itself as static (static module foo; for the above
example), and when you import it, it's automatically a static import.
More information about the Digitalmars-d
mailing list