Arrays passed by almost reference?

Leandro Lucarella llucax at gmail.com
Thu Nov 5 19:56:12 PST 2009


Travis Boucher, el  5 de noviembre a las 20:44 me escribiste:
> >>>I don't think that this is easy to explain to a learner; and I think that is a good indicator that there is a problem with these semantics.
> >>The ball is in your court to define better semantics.
> >
> >Just make arrays a reference value, like classes!
> 
> You mean dynamic arrays, but what about static arrays?

I would say "make them value types", but they already are ;)

> Sometimes it makes more sense to send a static array as a value rather
> then a reference (think in the case of small vectors).

That's why they already are value types.

> Then we'd have 2 semantics for arrays, one for static arrays and one
> for dynamic arrays.

Yes. They should have different semantics because they are different.

> I am not fully against pass-by-ref arrays, I just think in passing by
> reference all of the time could have some performance implications.

OK, make 2 different types then: slices (value types, can't append, they
are only a view on other's data) and dynamic arrays (reference type, can
append, but a little slower to manipulate).

It's a shame this idea didn't came true after all...

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
- i bet microsoft's developers were on diet when they had to do win95
- microsoft has developers?



More information about the Digitalmars-d mailing list