www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - property keyword

reply Gzp <galap freemail.hu> writes:
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";
Sep 25 2009
next sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Gzp wrote:
 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:

Hello, and welcome! :) There was a HUGE discussion about this not so long ago. Check out the newsgroup archives for August and July -- it's all about properties... http://www.digitalmars.com/d/archives/digitalmars/D/index.html -Lars
Sep 25 2009
parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Lars T. Kyllingstad wrote:
 Gzp wrote:
 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:

Hello, and welcome! :) There was a HUGE discussion about this not so long ago. Check out the newsgroup archives for August and July -- it's all about properties...

Late July and early August, that is. -Lars
Sep 25 2009
parent Gzp <galap freemail.hu> writes:
Thanks, i've found it.

Gzp
Sep 25 2009
prev sibling next sibling parent Chad J <chadjoan __spam.is.bad__gmail.com> writes:
http://prowiki.org/wiki4d/wiki.cgi?DocComments/Property
Sep 25 2009
prev sibling parent BCS <none anon.com> writes:
Hello Gzp,

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

Hi!
 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;
     }
   }
   int member;
 }

Personally, while I agree there are issues with using using function directly as properties, I think readability is one of the reasons that it it a GOOD idea. I find the current solution MORE readable than the C# like syntax you used.
Sep 25 2009