Properties

Bill Baxter wbaxter at gmail.com
Sun Jan 11 13:12:59 PST 2009


On Mon, Jan 12, 2009 at 4:07 AM, "Jérôme M. Berger" <jeberger at free.fr> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Andrei Alexandrescu wrote:
>> Miles wrote:
>>> Daniel Keep wrote:
>>>> Yes, property syntax can simplify some cases, but this isn't one of
>>>> them.
>>>
>>> One good distinction properties and normal functions ought to make is
>>> that functions should never be called without (), and properties should
>>> never have () unless it has a function type.
>>>
>>> Current syntax allows crazy things like:
>>>
>>> ----------
>>>     exit = 1;    // it is not an assignment
>>>     x = toString = getenv = "PATH";    // creepy, but valid D
>>>
>>>     if (fork == 1)    // not comparing the value of a variable
>>> ----------
>>
>> Walter and I see eye to eye that a possible solution would be to only
>> allow the a = b syntax as an alternative for a(b) only if there's also a
>> function a(). All of the above can be fixed within that framework.
>>
>        Won't work: how do you then create a write-only property?

I'm guessing they thought of that and the answer is you can't, but
write-only properties are a rare corner case.

But either way, it doesn't solve the ambiguity problem.  A callback
setter/getter pair will still run into trouble because you can't tell
if the getter wants to get the callback or actually call it.

--bb



More information about the Digitalmars-d mailing list