Properties

Daniel Keep daniel.keep.lists at gmail.com
Sat Jan 10 16:48:57 PST 2009



Nick Sabalausky wrote:
> "Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message 
> news:gk9v33$1bvu$1 at digitalmars.com...
>> [snip]
>> 
>> What would be the point of making a special syntax when you can already do 
>> that? :P
>>
> 
> Same reason we have "while" and "foreach" in addition to "for".
> 

How is this:

property int foo
{
     get
     {
         return compute_value();
     }
}

Appreciably better than this:

int foo()
{
     return compute_value();
}

We have for and foreach because iteration is a *very* common use for a 
loop, and you can screw it up when using while.  In this case, having 
property syntax for a computed field doesn't buy you anything whatsoever 
apart from more typing.

Yes, property syntax can simplify some cases, but this isn't one of them.

   -- Daniel

P.S.  Please don't get my hopes up by quoting my entire post and then 
only replying to one line; I thought I'd get to argue about my "80%" if 
nothing else.  :P



More information about the Digitalmars-d mailing list