byKey and byValue: properties or methods?

Jonathan M Davis jmdavisProg at gmx.com
Tue Jan 17 01:49:22 PST 2012


On Tuesday, January 17, 2012 09:07:04 Alex Rønne Petersen wrote:
> On 17-01-2012 07:48, 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
> 
> My thoughts:
> 
> The "by" in the name is way too awkward for a property. If it was just
> named "keys" and "values", it would've been perfectly fine to make them
> properties, but the "by" just looks awkward when you "call" them as
> properties.
> 
> As far as efficiency goes, I don't think these perform any work that is
> heavy enough to warrant not making them properties. (I can't say that
> same for .dup/.idup... I still don't get why those are properties, at all.)

Agreed. If it were keys and values, then a property would make sense. However, 
since it's byKey and byValue, I don't think that it makes as much sense. It 
_is_ a bit of a weird case though, since byKey and byValue are neither nouns 
nor verbs.

- Jonathan M Davis


More information about the Digitalmars-d mailing list