[phobos] returning void[] from std.file.read()

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 25 18:26:46 PDT 2010


On Saturday 25 September 2010 14:17:58 Andrei Alexandrescu wrote:
> This has come up in http://d.puremagic.com/issues/show_bug.cgi?id=1482.
> Should std.file.read() return void[] or ubyte[]? There's one matter with
> assuming that void[] may contain pointers (which is not the case for
> something read from a file), so possibly ubyte[] is a more accurate type
> for describng raw bytes.
> 
> What are the pros and cons of returning void[] vs. ubyte[]?

The biggest pro to returning ubyte[] is that it's not so confusing as to what on 
earth is being returned (what does void[] really mean anyway? It's pretty 
totally unusable unless you cast it). Also, ubyte[] would be properly indexable, 
and I don't think that void[] is, since void doesn't have a size by which to 
index. I'm not quite sure why you'd actually *want* void[], since ubyte[] is 
useable, void[] is not, and you're probably going to have to cast it to 
something else anyway (or use File's rawRead() instead of std.file.read(), as was 
suggested to me when I asked about this on D.Learn recently - though that could 
certainly use some enhancements).

- Jonathan M Davis


More information about the phobos mailing list