D component programming is a joke (Was: Re: Component programming)

Timon Gehr timon.gehr at gmx.ch
Fri Aug 2 16:27:20 PDT 2013


On 08/03/2013 12:02 AM, H. S. Teoh wrote:
> On Thu, Aug 01, 2013 at 10:49:00PM -0700, Walter Bright wrote:
>> On 8/1/2013 10:24 PM, H. S. Teoh wrote:
>>> Once this last bit worked, though, everything fell into place quickly.
>>> After all unittests were passing, no more bugs were found!! The program
>>> can print beautifully laid out calendars with no problems whatsoever.
>>> I'm so in love with D right now... If I'd done this exercise in C or
>>> C++, I'd be spending the next 2 days debugging before I could present
>>> the code for the world to see. D ranges and unittest blocks are t3h
>>> k00l.
>>
>> I think this is awesome, and this + your previous post are
>> sufficient to create a great article!
>
> OK, here's a draft of the article:
>
> 	http://wiki.dlang.org/User:Quickfur/Component_programming_with_ranges
>
> It looks like I may have to sort out some issues with compiler bugs
> before officially posting this article, though, since the code
> apparently fails to compile with many versions of DMD. :-(
>
>
> T
>

Also, you may want to replace some of the manually implemented ranges 
where this makes sense.

Eg, datesInYear can be expressed more to the point as:


auto datesInYear(int year){
     return Date(year,1,1).recurrence!((a,n)=>a[n-1]+1.dur!"days")
         .until!(a=>a.year>year);
}



(This closes over year though. The following version uses only closed 
lambdas by embedding year in the returned range object:


auto datesInYear(int year){
     return Date(year,1,1)
         .recurrence!((a,n)=>a[n-1]+1.dur!"days")
         .zip(year.repeat)
         .until!(a=>a[0].year>a[1]).map!(a=>a[0]);
})



More information about the Digitalmars-d mailing list