byKey and byValue: properties or methods?

Nick Sabalausky a at a.a
Mon Jan 16 23:18:12 PST 2012


"Nick Sabalausky" <a at a.a> wrote in message 
news:jf36tf$g3g$1 at digitalmars.com...
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
> news:jf35jr$e2k$1 at digitalmars.com...
>>I hate I must ask this:
>>
>> int[string] aa;
>> foreach (k; aa.byKey) { ... }
>>
>> or
>>
>> int[string] aa;
>> foreach (k; aa.byKey()) { ... }
>>
>
> Property. It's not an action, you're just accessing a particular interface 
> of aa.
>

Another way you can look at it to make it clear: As far as the caller is 
concerened, it would have made equal sense if byKey were implemented as a 
nested struct. Ie, it's data, not action. Just because your implementation 
happens to involve an imperative block of statements doesn't change the 
user's perspective of byKey's semantics.

Nick "Yes, it is still clear-cut" Sabalausky ;)




More information about the Digitalmars-d mailing list