www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: byKey and byValue: properties or methods?

 The builtin associative arrays of D.=A0 i.e.:
=20
 int[string] aa;

I could tell it was a container. Guess this shows how far I'm not looking = (or behind) with the details of implementation.
 If key, it must be read only, since keys must be immutable.
=20
 If value, it could potentially be read/write.

That's what I thought... I'd think keys could be mutable; However the hash= would have to be recalculated afterwards. That would be for very rare proj= ects (effectively removing it, adding it back in), but I don't really see i= t happening. Manually doing it is likely safer and easier to follow.
 properties are methods.=A0 There should be a way to pass
 a delegate to a=A0=20
 property function, not allowing this would be unnecessarily
 limiting.=A0=A0=A0
 Some sort of __traits directive comes to mind...

Yes I know that part. Just go with what makes the most sense. In my mind s= omething should be a property if it doesn't do anything really, and has spe= cific limitations on what it decides to do; Example: A Getter: Like (.length), you get the length/size and that's it. No side e= ffects, no generating new objects (not counting dup) A Setter (or lack of): Returning void (or the object/structure called), Ma= y change the structure, but only doing exactly what you expect it to do. I guess more importantly I'd need an example of how passing a method like = that to a delegate could be useful. I'd need a reasonable example, not just= syntax. The only time that might be useful, like if somewhere in the calli= ng it might change size; But for arrays that can reallocate then you may en= d up with the old array and not the newer one defeating the purpose. I'll leave whatever decisions to you guys. And I'm glad to see how fast bu= gfixes have been progressing recently.
Jan 24 2012