printf and global namespace

Anders F Björklund afb at algonet.se
Tue May 2 02:21:44 PDT 2006


Lionello Lunesu wrote:

> For easy debugging it would be better to add a void println(char[]) 
> function. That's what newbies really want, not printf("%.*s\n",x) and 
> also no writefln("%s",x) to handle %* in the string correctly.

Q: What was wrong with "std.stdio.writeln", as the name for it ?
Just seemed more fitting, writef (with format) => write (without)

My old stdio hacks are still at http://www.algonet.se/~afb/d/stdio/,
[see http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/21692]
and Sean Kelly's versions are still at http://www.home.f4.ca/sean/d/
[see http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/11021]


But even if std.stdio isn't cleaned up, "printf" should still die!
(again, that is: in object.d - it should move back to std.c.stdio)

Otherwise you get this: "maybe I should use writef, but since I have
to use an import then - I think I'll just use implicit printf instead"
mentality, and we'll have to insert those "import std.c.stdio;" later ?
I've already done so for Phobos once, but it is needed to do so again.


I think the offical Digital Mars docs should "lead by example", and use:

import std.stdio;
void main()
{
     writefln("Hello, World!"); // <-- Even better, use "writeln" here
}

Instead of the current hacks, which just looks like C always has done:

int main()
{
     printf("hello world\n");
     return 0;
}

It leads people to think "oh, printf works with D strings" --> *KABOOM*

--anders



More information about the Digitalmars-d mailing list