El 20/01/2012 18:58, Andrei Alexandrescu escribió:
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()) { ... }
I vote properties.
The general rule to me the is a function represents an *action* and
usually has a verb in its name while a property is logically something
of an object and its name is basically a noun, but nothing is said about
whether that thing is stored (a field). A function *does* something, a
property *is* something. I'm using "is" in a special way maybe because
property values might not actually exist and be created/computed on the fly.
"circle.area" is the area of a circle. Whether its value is stored or
computed on the fly does not change that.
aa.byKey is a range of keys, so, property.
Even "a.dup" *is* "a duplicate of a" so it's OK as a property even if it
is not a "part" of a. Emphasis on the action of creating that duplicate
is removed.
BTW, someone said that properties bring something more to remember (is
it a.b or a.b()?) but I think they actually reduce doubts:
How would I change the radius of a circle in another language?
circle.setRadius(2), circle.SetRadius(2), circle.set_radius(2),
circle.radius_set(2)? With properties "circle.radius=2;" easier to remember.
My two cents.