On 30.12.2011 07:36, Andrei Alexandrescu wrote:
On 12/30/11 12:25 AM, Derek wrote:
On Fri, 30 Dec 2011 16:22:49 +1100, Don <nos...@nospam.com> wrote:


Some names are better than others. But are they part of the API?
That's the issue.

Yes, that is an issue.

Often, parameter names (such as in sin(x)) are arbitrary and
meaningless. This is fundamental: the parameter names are arbitrary in
mathematics.

Why is that? I just assumed that it was because mathematicians did a lot
of repetitive handwriting and thus brevity was important to them.

Well one non-partisan opinion (in any direction) is I've recently played
with e.g. Python's POpen
(http://docs.python.org/library/subprocess.html#subprocess.Popen). It's
quite comfy to be able to say stdout=somefile, stderr=somefile instead
of enumerating arguments and relying on order to make them sensible.

Using such functions is not math, but is part of writing programs.

There are definitely cases when you can create a much nicer API, when you can use named parameters. This is particularly true of flags, and where there are default parameters. But I think that (a) it's not _all_ functions; and (b) you probably want to use named parameters consistently. I think it would be poor form to write these two lines in the same module:

 Popen(args, None, None, somefile, somefile);
 Popen(args, stdout : somefile, stderr : somefile);

so in the particular example of Popen, I think *requiring* all those parameters to be named in all calls wouldn't be a bad thing. Dunno if that's true in general though.

Note that in C/C++ you can easily create a header file where the parameters aren't named. But that isn't really available in D.
So there isn't even an opt-out mechanism.

I think: there are cases when named parameters are beneficial. There are cases where they are detrimental. Is it possible to get the first, without the second, and without much complexity? (I'm thinking of something like, a colon before the parameter name means the name is part of the API).

Reply via email to