property keyword

Gzp galap at freemail.hu
Fri Sep 25 02:04:56 PDT 2009


Hello,

I'm quite new to D, and it seems to be a great language for me.
But I've some questions:

Why is it good to treat functions as property, it make the code quite
unreadable. With a simple property keyword the things were much clear, like:

class Foo {

  property prop {
    int get {
      return a;
    }

    set(int value) {
      member = value;
    }

    // or optionally a cast like feature
    // it might induce some error
    // so the cast might not be possible here (just an idea)
    //
    //string get() {
    // return member.convertToString();
    //}
    //
    //set( string value) {
    // member = value.convertToInt();
    //}
  }

 int member;
}

...

Foo f;
f.prop = 1;
f.prop = "1";




More information about the Digitalmars-d mailing list