Properties

Miles _______ at _______.____
Sat Jan 10 19:01:18 PST 2009


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.

> 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.

> even moreso when chaining them such as foo.bar.baz vs. foo().bar().baz().

>From your example, it appears that the purpose of foo and bar, and
perhaps baz are to return instances, so they could just be turned into
properties, and have the exact syntax you expect.

> So?  The spec is not there to prevent people from doing stupid things (making it
> harder to do stupid things *by accident* is a reasonable goal, but we're all
> consenting adults here).  Anyone who would actually do stuff like this on purpose
> in their code is an idiot and deserves what they get.  One could just as easily do
> some pretty stupid things with operator overloading, casts, templates, you name
> it.  Just because stupid things *can* be done with a feature doesn't mean the
> feature should be removed.

You seem to be missing the point. In fact, you ignored the most
important example in my previous message that shows how the current D's
property syntax can be damaging.

Also, your reasoning fails to take into account the difference between
_allowing_ a certain syntax, and _incentivating_ bad usage.



More information about the Digitalmars-d mailing list