byKey and byValue: properties or methods?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Jan 20 10:43:54 PST 2012
On Friday, January 20, 2012 11:58:28 Andrei Alexandrescu wrote:
> On 1/17/12 12:48 AM, Andrei Alexandrescu wrote:
> > I hate I must ask this:
> >
> > int[string] aa;
> > foreach (k; aa.byKey) { ... }
> >
> > or
> >
> > int[string] aa;
> > foreach (k; aa.byKey()) { ... }
> >
> >
> >
> > Thanks,
> >
> > Andrei "I told you" Alexandrescu
>
> I tallied the votes.
>
> Function: Mail Mantis, bearophile, Jacob Carlborg, Olivier Pisano, Ary
> Manzana, torhu.
>
> Property: Nick Sabalausky, Simen Kjaeraas.
>
> I wasn't able to discern a clear vote from the others. Please correct
> the list.
I'm divided. If it were keys and values, I'd be all for property, but byValue
and byKey are weird property names. Of course, they're weird function names
too. I assume that they essentially stand for iterateByValue and iterateByKey,
which would be more of a function name, but they don't really iterate. Rather,
they return something which you can iterate over.
So, from a usage perspective, it definitely makes more sense as a property, but
from a naming perspective, it's a bit off. I don't really have a better
suggestion though, since values and keys are already taken. So, I'm fine with
it either way. There's going to be something weird about it regardless.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list