www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Broken UFCS Sucks

reply "Nick Sabalausky" <a a.a> writes:
Just need to vent a little about this...

This is very nice:

class Foo
{
    string doSomething(string str)
    { return ...; }

    void blah(int[] arr, string[] defines)
    {
        auto a = arr .filter!"a<10"() .map!"a*2"() .reduce!"a+b"();
        auto b = defines.map!`"--define="~a`() .join(" ") .to!string() 
.doSomething();

        // ---- or ----

        auto a = arr
            .filter!"a<10"()
            .map!"a*2"()
            .reduce!"a+b"();

        auto b = defines
            .map!`"--define=" ~ a`()
            .join(" ")
            .to!string()
            .doSomething();
    }
}


...except for the fact it don't work. Instead, we do:

class Foo
{
    string doSomething(string str)
    { return ...; }

    void blah(int[] arr, string[] defines)
    {
        auto a = reduce!"a+b"( map!"a*2"( filter!"a<10"(arr) ) );
        auto b = doSomething( to!string( join(map!`"--define=" ~ 
a`(defines), " ") ) );

        // ---- or ----

        auto a = reduce!"a+b"(
            map!"a*2"(
                filter!"a<10"(arr)
            )
        );
        auto b = doSomething(
            to!string(
                join(
                    map!`"--define=" ~ a`(defines),
                    " "
                )
            )
        );

        // ---- or ----

        // ..."make a bunch of useless temps" example omitted b/c I don't 
feel like writing it...
    }
}

Fucking butt-ugly. (Translation: Next-to-impossible to read.)

That's all I wanted to say.  /transmission-end
Oct 20 2011
parent Peter Alexander <peter.alexander.au gmail.com> writes:
On 21/10/11 7:27 AM, Nick Sabalausky wrote:
 Just need to vent a little about this...

 This is very nice:

          auto a = arr
              .filter!"a<10"()
              .map!"a*2"()
              .reduce!"a+b"();
Can't you do auto a = pipe!(filter!"a<10", map!"a*2", reduce!"a+b"); ??? Still not quite as nice syntax, but better than all the nested parens.
Oct 21 2011