[Issue 1985] import expression should return ubyte[] not string
Frank Benoit
keinfarbton at googlemail.com
Fri Apr 11 07:37:34 PDT 2008
Aarti_pl schrieb:
>> Your argument is right on, but ubyte[] *is* the type that means "I
>> don't know
>> what the heck this data is, but it's just data, not pointers". void[]
>> means "I
>> don't know what the heck this data is, it might even be full of
>> pointers". I don't see any way that file that is on disk at *compile
>> time* could contain
>> pointers that are relevant to the program later on at *run time*. So
>> ubyte[]
>> is the proper type.
>
> I think I understand your way of thinking. But the problem here is
> different. With void[] you can not do anything, so you have to cast.
> With ubyte[] you can use data as they are, because they have in fact
> specific type. But what if file contains array of int's? In such a case
> you are in exactly same situation as with char[]. Compiler chooses one
> type to which it casts by default, exactly like currently with char[].
> And this choice can be wrong. If it is good or wrong depends only on
> application. In GUI ubyte[] is more appropriate (e.g. importing icon),
> but in DB framework string is better (importing db schema).
>
> Having written this all I slowly get to conclusion that current
> situation is not so bad :-) char[] would be usually much more
> appropriate for lower layers in application than ubyte[] (mostly for
> loading and compiling domain languages). Alternative with void[] is IMHO
> theoretically better, but practically you will have even more casts in
> you code... Tough decision... :-)
foreach( c; import("data")){
// do something
}
- cannot work with void[]
- will always work in a reasonable way with ubyte[]
- might throw UnicodeException with char[]
More information about the Digitalmars-d-bugs
mailing list