printf and global namespace
Don Clugston
dac at nospam.com.au
Fri Apr 28 08:14:53 PDT 2006
mclysenk at mtu.edu wrote:
> Does printf really need to be in the global namespace anymore? Now that writef
> is fully developed, it seems obsolete. I would say that using printf in a
> newer D program is bad style, since writef is much safer and neater. It also
> gives new programmers the wrong idea. Often they'll try to printf dynamic
> character arrays with a "%s", which surprisingly works most of the time, but
> fails whenever the string has no null terminators.
>
> The only disadvantage to this would be breaking some older programs, but they
> could be fixed by just adding an import std.c.stdio . I say that all of the old
> C stdio functions should get out of the global namespace, and back into their
> module where they belong.
>
> -Mik
I agree. It's a newbie trap.
I consider this to be entirely different from the recently discussed
issue about whether it's OK for Object to use printf.
Personally, I'm don't really care about how Object is implemented, but I
think it's a real problem that an obsolete function is implicitly
declared in every D program.
One issue, though, is the use of
debug printf() all through Phobos.
Since there's no 'debug import' statement, we could
create a file
std.c.debugstdio
consisting of:
-------------------------
module std.c.debugstdio;
version(debug) {
extern (C)
{ /// C's printf function.
int printf(char *, ...);
}
}
-------------------------
and add this to the top of every Phobos file.
More information about the Digitalmars-d
mailing list