@property - take it behind the woodshed and shoot it?

Timon Gehr timon.gehr at gmx.ch
Thu Jan 24 14:52:29 PST 2013


On 01/24/2013 08:03 PM, Artur Skawina wrote:
> ...
>
> Having said that, I'll elaborate on the sentence you quoted above. See for example
> Timon's code [1] here: http://dpaste.dzfl.pl/baa538af . Spot the recursion in the
> tree-walker. This is an example of the kind of abuse of parens-less calls that an
> unsuspecting programmer shouldn't have to deal with. Sure, in this case it's simple
> enough, but in more complex scenarios, where the 'inorder' field/method/ufcs
> definition is not readily available, it would be extremely misleading. It's not
> reasonable to expect everyone reading the code to check every single object field
> access, just in case the previous coder decided that the source looked "cuter"
> w/o the '()'.
> ...

Uh...

class Tree(T){
     InOrder!T inorder;
     this(){inorder = InOrder!T(this); }
     Tree!T l,r;
     T v;
}
auto tree(T)(Tree!T l, T v, Tree!T r){
     auto t = new Tree!T;
     t.l=l;t.r=r;t.v=v;
     return t;
}
auto tree(T)(T v){ return tree(Tree!T.init,v,Tree!T.init); }
struct InOrder(T){
     this(Tree!T c){container=c;}
     Tree!T container;
     InOrder* t;
     mixin Yield!(q{
         if (container.l !is null){
             for(t=[container.l.inorder].ptr;!t.empty;t.popFront())
                 yield t.front;
         }
         yield container.v;
         if (container.r !is null){
             for(t=[container.r.inorder].ptr;!t.empty;t.popFront())
                 yield t.front;
         }
     },T);
}
//InOrder!T inorder(T)(Tree!T container){ return InOrder!T(container); }



More information about the Digitalmars-d mailing list