Proposal request: explicit propreties

Simen Kjaeraas simen.kjaras at gmail.com
Tue Apr 1 07:48:11 PDT 2008


On Tue, 01 Apr 2008 15:21:19 +0200, Ary Borenszweig <ary at esperanto.org.ar>  
wrote:

> Finally, there is another reason for wanting to mark functions as  
> properties: when you do autocompletion in an IDE, and it suggests you a  
> function, it can't know whether to autocomplete it as a function or as a  
> property. A solution could be writing something in the ddoc of that  
> function, but since there's no standard for this, each IDE will invent  
> it's own.
>
> Of course, this is not backwards compatible, so it should be a D2  
> feature.
>
> What do you think?

I like it the way it is. It's simple and, for the most part, logical.  
Though as
you say, it might be a problem for IDEs. However, I think if D should have
properties, that one should be able to customize them more. I've been  
working on
a property struct template, which allows you to customize its access (i.e
read-only, write-only, allow only certain operators...), as well as mixin
fuctions of your choice. And the syntax is pretty simple (though not  
perfect. I
wish there was some way to have it set up automagically, not in the
constructor):

   class foo
   {
     private:
       int _bar;
       float _baz;
     public:
         // read-write property
       property!(int, property.readwrite) bar;
         // custom property that allows only addition and subtraction
       property!(float, property.custom, "+,-", "+,-", "+=, -=") baz;

     this()
     {
       bar = &_bar;
       baz = &_baz;
     }
   }

   foo f = new foo;
   f.bar += 3;

I believe something like this would be more useful, as long as there were  
some
standard way to do it. Also, the syntax to mixin templates could do with  
some
sugar. What I'd really want'd be something like this:

   class foo
   {
     private:
       int _bar;
       float _baz
       string _faz;
     public:
       property!(_bar) bar;
       property!(_baz, read) baz;
       property!(_faz){
         // methods to be mixed in
       } baz;
   }


--Simen



More information about the Digitalmars-d mailing list