[Design] return char[] or string?

Regan Heath regan at netmail.co.nz
Wed Aug 22 01:58:44 PDT 2007


Stewart Gordon wrote:
> Regan Heath Wrote:
> 
> <snip>
>> As for your cases mentioned above...
>> 
>> I would probably implement (c), a property setter, as code that
>> sets the member followed by a call to the getter so it would return
>> the same as (b).  That said I haven't written a lot of these so
>> perhaps my experience using them isn't sufficient.
> 
> I've never really liked this idea.  In general, either it would just
> return the same string that was passed in, IWC there's no point
> calling the getter rather than simply returning the argument

I'd hope the call to the getter would be inlined.

The point I see is consistency, the getter might return the stored value 
with some sort of modification, perhaps due to a change in required 
functionality at some point, or perhaps because more than one getter 
uses the same data member.

 >, or
> there would be a performance hit where the return value isn't used.

Yeah, that's always going to be a problem.  It's a pity we cannot 
overload on return type.

> Much better would be if D would chain property assignments
> implicitly:
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/10199.html
> 
> If only Walter would finally answer this request (among many others)!

Yeah, this is another of those cases where a property doesn't quite work 
the same as a plain old data member, p.property += x; being the more 
common one.

Regan


More information about the Digitalmars-d-learn mailing list