Properties
Bill Baxter
wbaxter at gmail.com
Sat Jan 10 19:17:45 PST 2009
On Sun, Jan 11, 2009 at 12:01 PM, Miles <_______ at _______.____> wrote:
> dsimcha wrote:
>> I for one think that code is often more
>> readable without the annoying empty parentheses around functions that don't take
>> any arguments.
>
> It introduces ambiguities, and unexpected behavior, as I exemplified in
> the previous message.
>
> Parentheses (when following an identifier) has a precise meaning of
> calling the named function. That is something most modern procedural
> languages do, it is something programmers are used to.
>
> I see no advantage at giving the privilege to no-argument functions of
> being called without parentheses, while at the same time you lose the
> ability to distinguish between _calling_ the function from _referring_
> to it.
Not sure what you mean by that. It's just foo vs &foo in most cases.
...Except for some cases like where you're trying to return a delegate.
I agree that 'except for' is not very pleasant.
>> This is especially true for member functions of classes and
>> structs,
>
> Aren't these member functions good candidates to be made into real
> properties?
>
> If you want or need to use an identifier without parentheses, you have
> the option of making it into a property. Very simple.
He may want to retain the ability to pass it as a delegate to some
other function too. If you make properties distinct from functions,
then I don't think this can be allowed. So you'd need to have the
property and a function that wraps the property. Then you've just
made more work for yourself. Hmm, maybe properties should be
allowed to be turned into delegates.
--bb
More information about the Digitalmars-d
mailing list