Proposal request: explicit propreties

Lionello Lunesu lionello at lunesu.remove.com
Tue Apr 1 17:42:58 PDT 2008


"Ary Borenszweig" <ary at esperanto.org.ar> wrote in message 
news:fsti15$a9s$1 at digitalmars.com...
> Lionello Lunesu wrote:
>> The whole point of property is that you can simply leave it as a function 
>> and the compiler will inline it if it turns out to be a trivial get/set. 
>> You're reasoning here is the wrong way around.
>
> To me, the idea of a property is: you use it as it were a field of a 
> struct/class, but it's actually implemented by a function. You want to 
> hide the implementation details from the user. You don't want them to know 
> "Foo.property" is actually a function.

That's what I meant: why would you ever want to change a property 'function' 
into a data member? You'll end up with less flexibility, and gain nothing.

> Take a look a this, from DFL:
>
> ---
> class Form {
>
>   /// Sets the title of this form
>   void title(string text) {
>     // ...
>   }
>
> }
>
> class Application {
>
>  /// Runs an application whose main form is the given
>  static void run(Form form) {
>    //
>  }
>
> }
> ---
>
> Now you wan to code:
>
> ---
> Form form = new Form();
> form.title // <-- you wan't the IDE to suggest you a property, so
>            // you will end up having "form.title = text"
>
> Application.run // <-- you wan't the IDE to suggest you a function,
>                 // like "Application.run(form)"
>                 // "Application.run = form" looks ugly, and no one
>                 // would recommend you to write that
> ---
>
> How do you configure this? On a per-property basis?

It appears that in both cases the user has knowledge whether the member 
should be assigned or invoked. The IDE will simply suggest "title" or "run" 
and pressing "=" or "(" key will finish the job, yielding either "title=" or 
"run(".

Unless you mean the IDE should have suggested the "=" and "(" as well, but I 
have never seen an auto-complete that suggests more than just the name. And 
it sounds like it shouldn't suggest more than that; what if I want a ptr to 
member function?

My suggestion for a user setting applies to getters. There, when the IDE 
shows a suggested function/getter, pressing ";" will finish the line and 
optionally add a pair of ().

L. 




More information about the Digitalmars-d mailing list