Design with appender: good or bad?

Rene Zwanenburg renezwanenburg at
Thu Apr 10 03:47:07 PDT 2014

On Thursday, 10 April 2014 at 10:16:43 UTC, Chris wrote:
> Ah, this one \me (= escaped me). Sorry I wasn't precise, I was 
> wondering if it is in any way dangerous to have
> @property string[] items() {
>   return;
> }
> instead of:
> string[] items;
> // ...
> public addItem(string item) {
>   items ~= item;
> }
> because the two are not the same. When you print MyStruct to 
> console you get the address of appender buf, whereas when you 
> use string[] items you get the actual items. I'm only 
> wondereing if using appender is potentially dangerous and could 
> bite me later.

The only thing I know of is if you store the reference returned 
by items(), clear the appender, and add new items, the contents 
of the previously returned slice will change too. Clearing an 
appender is similar to setting slice length to 0 and calling 
assumeSafeAppend on it.

More information about the Digitalmars-d-learn mailing list