Bug 5043 – writeln with empty arrays should write something useful
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-11T15:29:00Z
Last change time
2012-11-29T08:04:16Z
Keywords
patch
Assigned to
andrei
Creator
peter.alexander.au
Comments
Comment #0 by peter.alexander.au — 2010-10-11T15:29:18Z
writeln( [1, 2, 3] ); // prints "[1, 2, 3]"
writeln( [] ); // prints "" (nothing)
Why doesn't writeln( [] ) print "[]"? It seems to me that "[]" would be far more useful, and it is certainly more consistent with the non-empty array behaviour.
I know this is a minor thing, but if I'm trying to debug, blank lines aren't very much use, and actually cause more confusion than enlightenment.
Comment #1 by bearophile_hugs — 2010-10-11T16:19:36Z
The same bug is present with associative arrays:
import std.stdio: writeln;
void main() {
int[int] aa;
writeln(aa);
}
In this case I expect an output like:
[]
or even:
[:]
See also bug 3813
Comment #2 by denis.spir — 2010-12-16T00:24:11Z
(In reply to comment #0)
> writeln( [1, 2, 3] ); // prints "[1, 2, 3]"
> writeln( [] ); // prints "" (nothing)
>
> Why doesn't writeln( [] ) print "[]"? It seems to me that "[]" would be far
> more useful, and it is certainly more consistent with the non-empty array
> behaviour.
>
> I know this is a minor thing, but if I'm trying to debug, blank lines aren't
> very much use, and actually cause more confusion than enlightenment.
+++