Revised RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Oct 2 06:20:47 PDT 2008
Bruno Medeiros wrote:
> Sergey's argument (which is much more objective than subjective) is not
> strictly against omitting parenthesis, but rather against ambiguity (the
> dual possible ways to call zero-args functions), which as has been
> shown, creates various possibilities for bugs when you mix functions
> that return delegates. This ambiguity problem would also be resolved if
> omitting parenthesis would be *the only way* of calling functions with
> zero-args.
Yah, he made great points. There are ambiguities. The counter-argument
is that that would make the syntax of calling functions with no
arguments inconsistent with the syntax of calling function with
arguments. The "()" is a degenerate case of "(a, b, c)". So it's hard to
keep everybody happy.
> Anyways, I also agree with principles 1 and 2. But I also agree with
> some other principles that sometimes conflict with those first ones
> (which is what is happening here). And in each such scenario I would
> have to weight in to see which principle I would give priority.
Yes, there are other principles to follow too. And somehow they often
participate in a weighted average in many design decisions.
> These other principles are:
>
> 3 - Consistency of syntax - The same language feature should use the
> same syntax, with as little variations as possible.
>
> This principle fails here because when you have functions with
> parameters you have to use parenthesis, and only when you don't have
> arguments you omit the parenthesis. But the zero-args case should not be
> different from the n-args case. Of course, this could be solved by
> having a syntax for the n-args case that also doesn't use parenthesis
> (see my OP after Benji's thread)
Great. Yes, that is consistency. I swear that all I wrote above was
before I saw this :o).
> But most importantly:
> 4 - Common ground with other programming languages. There are several
> things that are common with many, if not all, of the mainstream
> programming languages (Java, C#, C/C++, Ruby, Python, etc.).
> One of them is using parenthesis for calling functions! (See KennyTM's
> post with the table describing function calling for several languages.)
> Using parenthesis comes from math. And of that list, only VB 6, Pascal
> and Perl, have the possibility of omitting parenthesis. And frankly, VB6
> and Pascal don't matter since they are pretty much obsolete. And Perl is
> language with a hack-ish nature, IMO. Even Lisp uses parenthesis for
> function calling! (even if in a different position, and even if it's
> pretty much the only syntax it has).
> This is a subjective principle, I can't tell you to want to like having
> common ground with other languages, but c'mon... "writeln;"? Seriously??
> That's just hideous.
I agree that 4 is a good principle. I'd even call it "consistency" -
across languages that is. But let's not forget that C# defined an entire
feature - properties - to fulfill what was perceived as a need. Also the
Cecil language goes as far as requiring accessors for any field (and
defining methods implicitly when missing). Eiffel also has properties
that are obtained via syntactic conventions (getX and setX implement
property x). People want to add properties to Java 7 (unfortunately the
google search is clogged by a Java class called Properties so it needs
some combing).
I use writeln; all over the place, and more importantly obj.method,
without finding them hideous.
I'm impressed a lot by the analogy with math because it is one extra
argument in my favor. In math there's no function without arguments. At
most people would say f(.) (with a central dot) when referring to what
is akin to the address of the function.
Andrei
More information about the Digitalmars-d-announce
mailing list