Make dur a property?

Timon Gehr timon.gehr at gmx.ch
Wed Jan 23 13:53:45 PST 2013


On 01/23/2013 10:08 PM, Jonathan M Davis wrote:
> On Wednesday, January 23, 2013 21:54:54 Jacob Carlborg wrote:
>> On 2013-01-23 21:46, Jonathan M Davis wrote:
>>> I confess that it's syntax like that that makes dislike UFCS. I can see
>>> why
>>> you might like it, but personally, I find it to be hideous.
>>>
>>> But as long as you're not using -property, you can do 2.days to get a
>>> Duration of 2 days, much as I wish that you couldn't.
>>
>> The point is that the code should read like regular text.
>
> I know that that's what you're going for, but I don't agree with it at all.
> It's code, not a novel.
>

What is the point?

>> But if you do:
>>
>> auto t = ago(days(2));
>>
>> It's backwards
>
> I've programmed enough in functional languages (and in a functional style in
> non-functional languages) to find 2.days().ago() to be horribly backwards.
>

IMHO, this is ridiculous. Real Haskell programmers are flexible enough 
to use both orders.

sun^.position.x

>> but it's still better than:
>>
>> auto a = Time.now() - 60 * 60 * 24 * 2; // don't know the exact syntax
>
> Well, of course that's horrible. It's using naked numbers. The correct syntax
> would be
>
> auto a = Clock.currTime() - dur!"days"(2);
>
> or if you don't want to use dur
>
> auto a = Clock.currTime() - days(2);
>
> And I see no problem with that.
>
> - Jonathan M Davis
>

Likewise, there is no problem with 2.days.ago.

Clock.currTime() - dur!"days"(2) is more verbose without being more clear.


More information about the Digitalmars-d mailing list