My thoughts & experiences with D so far, as a novice D coder

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 28 19:39:45 PDT 2013


On Friday, March 29, 2013 03:11:08 Jesse Phillips wrote:
> The write function seems a little odd as it uses random access
> (indexing).
> 
> Instead of assigning to front like append does it assigns at
> index buffer[0]...

That's because it's operating on multiple bytes at a time (e.g. writing the
4 bytes of an int at once). Really, it's  written for arrays and was
generalized because it could be rather than really having been written for
ranges.

> The implementation of append is what you will find more in
> idiomatic D. In fact if the module was written today write
> wouldn't exist and append would probably have been named write.

That could be argued for, but write and append do different things and both 
exist for a reason. Only having append would actually be problematic, as there 
are cases where you really do need write and not append. And neither of them 
have been in Phobos for all that long (peek, read, write, and append were 
added in 2.060).

- Jonathan M Davis


More information about the Digitalmars-d mailing list