http://d.puremagic.com/issues/show_bug.cgi?id=3813



--- Comment #11 from Denis Derman <denis.s...@gmail.com> 2011-01-28 06:08:53 
PST ---
More generally, why don't writeln / formatValue / whatever builtin funcs used
for output simply recurse to format elements of collections. This is how things
work in all languages I know that provide default output forms. And this
default is equal, or very similar, to literal notation).
Isn't this the only sensible choice? I think we agree default output format is
primarily for programmer's feedback.

Side-point: I would love default formats for composites thingies like struct &
class objects as well. Probably another enhancement request. Currently, the
code copied below writes out:

S
modulename.C

Great! very helpful ;-) I wish we would get, as default, an output similar to
the notation needed to create the objects:

S(1, 1.1, '1', "1.1", S.Sub(1))
C(1, 1.1, '1', "1.1", new C.Sub(1))

(Except for members with default values, possibly not provided in creation
code, but listed on output.)

At least we can write a toString... but it's a bit annaoying to be forced to do
it, esp for quickly written pieces of code, when a default would do the job
(prbably most cases by far).

Denis

Code:

struct S {
    struct Sub {
        int j;
        this (int j) {
            this.j = j;
        }
    }
    int i;
    float f;
    char c;
    string s;
    Sub sub;
}

class C {
    static class Sub {
        int j;
        this (int j) {
            this.j = j;
        }
    }
    int i;
    float f;
    char c;
    string s;
    Sub sub;
    this (int i, float f, char c, string s, Sub sub) {
        this.i = i;
        this.f = f;
        this.c = c;
        this.s = s;
        this.sub = sub;
    }
}

unittest {
    S s = S(1, 1.1, '1', "1.1", S.Sub(1));
    writeln(s);
    C c = new C(1, 1.1, '1', "1.1", new C.Sub(1));
    writeln(c);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to