ufcs and integer params

Jonathan M Davis jmdavisProg at gmx.com
Sun Jul 15 11:56:57 PDT 2012


On Sunday, July 15, 2012 19:50:18 Timon Gehr wrote:
> On 07/15/2012 05:40 AM, Jonathan M Davis wrote:
> > On Sunday, July 15, 2012 05:30:55 Jay Norwood wrote:
> >> I see from this other discussions that it looks like 2.059 ( or
> >> maybe 2.060) does support something like 3.cm().   Not sure from
> >> the discussion if it would also accept 3.cm as in the xtext/xtend
> >> example.
> >> 
> >> http://forum.dlang.org/thread/smoniukqfxerutqrjshf@forum.dlang.org
> > 
> > UFCS (universal function call syntax) was added in 2.059. If cm is a
> > function, then 3.cm() will work. If it's a property function, then 3.cm
> > will work. If you don't compile with -property, then 3.cm will still work
> > with cm being a non-property function, but -property will become the
> > normal behavior eventually,  so you shouldn't expect that 3.cm will work
> > long term unless cm is a property function.
> 
> I expect it to stay.
> 
> Another reason why @property-'enforcement' is flawed:
> 
> @property auto cm(int arg){ .. }
> 
> cm=2;   // ok
> 2.cm;   // ok
> 
> The two code snippets would in fact be equivalent.

@property isn't perfect, and I admit that the fact that both cm = 2 and 2.cm 
works here is undesirable, given what's trying to be done here, but it makes 
sense given that it's abstracting a variable. It's just undesirable that you 
can't make it so that it functions only as a getter. But the overall situation 
is still a whale of a lot better than the laxity of letting just any function 
be called with or without parens depending no what each particular programmer 
feels like doing with it. If it's a property, it should be treated as such, 
and if it isn't, it shouldn't.

> What is enforced here? Why would it matter if anything is 'enforced'?

If you marked it as a property, then it's supposed to be abstracting a 
variable and should be treated as one, just like if it's a normal function, it 
should be invoked as a function, just like ++ shouldn't suddenly do --, and / 
shouldn't *.

I don't want to get into this argument again. The current plan is (and has 
been for some time) that -property will become the normal behavior, and there  
have been no indications that that's going to change. I know that you don't 
like it, but some of us think that it's a major improvement, even if the 
result isn't perfect. The only way that it's going to change is if Walter 
changes his mind.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list