Just because it's a slow Thursday on this forum

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 10 11:08:11 PST 2016


On Wed, Feb 10, 2016 at 06:51:21PM +0000, w0rp via Digitalmars-d wrote:
> I wonder if the addition of another function for printing will confuse
> some new users.

Currently I don't see much value in it to justify the costs.

BUT,

there might be a case for it if:

1) It's clear that it's only intended for debugging (i.e., the name
should make it clear it isn't for general output, so `dump` rather than
`print` would be preferable);

2) It's actually useful for debugging, meaning:

   a) It will use introspection to recursively output aggregate members
   (preferably with field members labelled);

   b) Arrays and AA likewise should be output in the expected format;

   c) Attributes, and perhaps the full type, should be included in the
   output, especially if function pointers and delegates are involved,
   e.g.:

	const(char)[] data = ...;
	int delegate(float) @safe dg;
	dump(data, dg);

   should output something like:

	(const(char)[])"Some string data", (int delegate(float) @safe)0x12345678

   (Why the full type? because it's useful for debugging `auto`
   variables in range-based code and other such code. And also to make
   it absolutely clear that this isn't meant for anything other than
   debugging output.)

   d) It will, optionally, walk recursive data structures and output
   each node in some sensible way.

3) The output format should be standard, readable by default, and should
not need (nor allow) customization. (Otherwise, we might as well go back
to writefln & friends.)


T

-- 
It is impossible to make anything foolproof because fools are so ingenious. -- Sammy


More information about the Digitalmars-d mailing list