Reddit: why aren't people using D?
Michiel Helvensteijn
m.helvensteijn.remove at gmail.com
Thu Jul 23 14:32:07 PDT 2009
Bill Baxter wrote:
> """
> I've always thought properties should work somewhat like this:
>
> property int length {
> get() { return this.len; }
> set(newLen) { this.len = newLen; }
> }
> """
>
> I'm curious. Is it just a coincidence that how you've "always
> thought" happens to look a lot like C# properties? Or did you mean
> to say "Ever since I saw how C# does properties I've thought...."?
Nope. Never used C#, never seen it. I just think about language design a
lot, and this is what I came up with. From that newsgroup thread, it seems
that they are still quite different from C# properties.
> In any event I think a problem with this is that for D's simple
> grammar to remain simple and context free, get and set would both have
> to be made keywords in the language.
I don't think so. They can just be identifiers with special meaning. If you
look a bit further down the thread, I suggest adding the 'auto' keyword
where the missing types are now. Perhaps that helps.
In fact, in the design of my own language, those names have special meaning
for all types:
get(x) (or x.get()) returns x itself.
set(x, v) (or x.get(v)) assigns v to x.
If you specify them in a property, you're just overriding their meaning for
the underlying type of the property, just like you can override other
member-functions. Another upside is that you can always count on these
functions existing for every type and you can pass them around as
functions/delegates.
--
Michiel Helvensteijn
More information about the Digitalmars-d
mailing list