in-parameter
Pillsy
pillsbury at gmail.com
Mon Nov 8 08:43:20 PST 2010
Jonathan M Davis Wrote:
[...]
> So, if you alter the elements of that array, it alters the elements of
> the array that was passed in. However, if you alter the arrays size,
> causing it to have to re-allocate memory, then that array is going to
> be pointing to a different block of memory, and it will no longer
> affect the original array.
This behavior, IMO, is a real misfeature. The length property of an array shouldn't be directly mutable, and you shouldn't be able to append onto the end of a dynamic array, because it can cause some surprising behavior and adds a lot of cruft to the interface in the form of, well, most of std.array. The ability to use an an array as a replacement for an ArrayList or std::vector clashes badly with the ability to use arrays as lightweight slices.
Since lightweight slices are such a win[1], and people coming from any of Java/C#/C++ will be used to using a library class if they need a flexible array to use as a list, I think separating the two concepts and moving the flexible array into a library would be a notable improvement to the language. Sure, it may surprise Pythonistas, but they'll have a lot to learn anyway, given how much lower level and more static D is as a language.
[1] From a "marketing" perspective, they're also great way to show off how using a GCed language can actually improve performance and memory use.
Cheers,
Pillsy
More information about the Digitalmars-d
mailing list