On 08/25/2011 04:08 AM, bearophile wrote:
Timon Gehr:

It is especially compact in that program,

The coding style of that program is an unreadable mess, example:

LList!T hamming(T)(){
     LList!T merge(LList!T xs, LList!T ys){
         return lz({
                 auto x=xs.head, y=ys.head;
                 if(x()<y()) return cons(x,merge(xs.tail,ys))();
                 else if(x()>y()) return cons(y,merge(xs,ys.tail))();
                 else return cons(x,merge(xs.tail,ys.tail))();
             });
     }

     return lz({
             LList!T r;
             r=cons(st(1),lz({return merge(merge(map((Lazy!T a){return 
lz({return 2*a();});},r),map((Lazy!T a){return lz({return 
3*a();});},r)),map((Lazy!T a){return lz({return 5*a();});},r))();}));
             return r();
         });
}


This is a bit better:

LList!T hamming(T)() {
     static LList!T merge(LList!T xs, LList!T ys) {
         return lz({
                 auto x = xs.head;
                 auto y = ys.head;
                 if (x()<  y())
                     return cons(x, merge(xs.tail, ys))();
                 else if (x()>  y())
                     return cons(y, merge(xs, ys.tail))();
                 else
                     return cons(x, merge(xs.tail, ys.tail))();
             });
     }

     return lz({
                 LList!T r;
                 r = cons(st(BigInt(1)), lz({
                     return merge(merge(map((Lazy!T a){ return lz({ return 2 * 
a(); }); }, r),
                                        map((Lazy!T a){ return lz({ return 3 * 
a(); }); }, r)),
                                  map((Lazy!T a){ return lz({ return 5 * a(); 
}); }, r))();
                 }));
                 return r();
             });
}


Well, the main reason it is an unreadable mess is the bug with lazy and closures I reported, and I think inserting whitespace does not necessarily make the code better readable. (I like especially the first half of the code snippet better in the format I provided)

I usually do not spend much time to format my code, especially if like here the end result is not significantly better readable. Maybe code formatting should be automated completely via a dedicated tool.



I am starting to think this is not as intended.

I think it's a DMD bug. Fit for Bugzilla.


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


I cannot seem to find it, but I'd like to vote on it. Do you have a link?

I have updated this:
http://d.puremagic.com/issues/show_bug.cgi?id=5970


Thanks.

Reply via email to