printf and global namespace

Lionello Lunesu lio at lunesu.remove.com
Tue May 2 01:54:20 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.

Agreed! It even complicates overloading printf for output to a file or 
window.

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.

A simple print[ln] would have the added benefit of adding a low 
foot-print to the executable when used. I know printf's not that big, 
but still, it seems way to heavy for simple printing.

puts seems similar to print but (1) uses zero-terminated strings and (2) 
no way to print text without the new-line.

L.



More information about the Digitalmars-d mailing list