const, final, scope function parameters

David B. Held dheld at codelogicconsulting.com
Mon May 28 01:16:43 PDT 2007


James Dennett wrote:
> Myron Alexander wrote:
> [...]
>> I think the one exception is strings in that the D implementation is an
>> array but conceptually, there is a difference of opinion for whether
>> strings are buffers or values. I am firmly on the "string is a value"
>> bench and have my wet trout ready to go slap the "other" side when the
>> mother of all wars begins :) (Actually, I have a nuke-lee-are trout that
>> is const, non-static, and very final ;))
> 
> My understanding is that in D, arrays (almost) have
> reference semantics.  It's a shame, IMO, but languages
> have to make choices and there's no way one language
> is going to make them all the way I would unless I
> design it myself (and I don't believe that I could
> successfully bring a language to a mass audience as
> Walter is attempting to do).

Actually, the intent is for string literals to be invariant arrays, 
which mean that they will be values implemented as reference types. ;) 
Hey, Java does it and it works just fine!  Walter chose to make D's 
arrays be references for performance reasons.  It is still possible to 
create C-style arrays with value semantics using pointers and structs 
(almost, as soon as structs get fixed).  However, since D relies heavily 
on arrays, it was important to make them fast by default (and passing 
arrays more than about 16 bytes large is almost certainly faster by 
value than by reference).  I've seen plenty of C++ noobs (and 
experienced coders) passing around std::vector<> by value out of 
laziness or ignorance or both.  At least users can't make that mistake in D.

Dave



More information about the Digitalmars-d mailing list