@property on free function for UFCS?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 14 09:36:53 PDT 2015


On Sun, 14 Jun 2015 18:21:39 +0200, Timon Gehr wrote:

>> only if you plan to use it like `foo = 5;`.
> 
> You can use it like that anyway.

sure, but i'm talking about style, not about compiler demands.


>> i.e. exactly like field variable.
> 
> struct S{
>      void delegate() dg;
> }
> 
> int main(){
>      S s;
>      s.dg=(){ writeln("!"); };
>      s.dg();
> }
> 
> Now show me the UFCS way.

i'm afraid i didn't understood you here.


>> compiler will not complain, but putting `@property` here is
>> stylistically wrong.
>>
> It's neither wrong nor right.

yet i never saw this:

  struct S { int n; }

  S s; s.n(42);

the whole concept of properties (not bolted into the compiler yet) is to 
emulate *fields*. so it's stylistically right to declare something as a 
property if one wants to use it like `foo = 42;`. that means `mymodule.foo 
= 42;` actually. yet `42.foo` means `42.module.foo`, which even looks 
wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150614/9c61b4af/attachment.sig>


More information about the Digitalmars-d-learn mailing list