On Sun, 02 Aug 2009 20:53:35 -0400, Michel Fortin <michel.for...@michelf.com> wrote:

On 2009-08-02 20:18:51 -0400, "Robert Jacques" <sandf...@jhu.edu> said:

I also like the idea of omitting parenthesis for functions with no argument.

I like it too. But the problem with the current approach D are:

1. A syntax that permits function to be called both without and with empty parenthesis creates ambiguities when it returns a callable type (a delegate or an object with an opCall member).

2. We want properties to be nouns, and actions to be verbs. In english a lot of words are both nouns and verbs, which makes it impractical to distinguish a property from a function by its name alone.

Solving 1 involves having a way to say functions that can and must be called without parenthesis. Unless we want to force all functions with no parameter to be called without "()", we must have some kind of flag to tell us that a function expects or does not expect "()".

Solving 2 involves making a difference in the call syntax between property and action functions. Since the idea behind a property is to mimic a field, it follows that the best differentiator for properties is the lack of parenthesis.

I'd be glad too if we could continue to skip parenthesis for calls to functions with no arguments, but I think fixing the two problems above is more important.


I agree 1) is an issue, but I view it as a corner case. (I use zero/one arg functions all the time and make use of the 'property' syntax left right and center, but I've never run into the opCall problem) It would be nice if it were fixed, but we may be cutting off the nose to spite the face, as it were. (Or alternatively, taking the scientific instead of engineering approach)

Problem 2) I think is a major logical flaw: a property is a function. So I see no need to distinguish between the two. Properties, in fact, can be a very expensive functions that takes locks/do database lock-up/etc. So making syntax changes that make 'properties' look cheap and 'functions' look expensive is worse than what we have today. Today, at least, everyone knows that no parenthesis doesn't mean necessarily cheap O(1) operation.

Solution 1 is what I thought you were proposing. Again, I like it, though it does make zero-arg function pointers and delegates behave differently than other functions. And disallowing free_function = expression; would also address another concern many people have expressed. (Strangely enough, using the invalid code snippet: writeln = 5)

Reply via email to