[swift-evolution] [late pitch] UnsafeBytes proposal
David Sweeris
davesweeris at mac.com
Mon Aug 15 18:14:37 CDT 2016
> On Aug 15, 2016, at 13:55, Michael Ilseman via swift-evolution <swift-evolution at swift.org> wrote:
>
> It seems like there’s a potential for confusion here, in that people may see “UInt8” and assume there is some kind of typed-ness, even though the whole point is that this is untyped. Adjusting the header comments slightly might help:
>
>
> /// A non-owning view of raw memory as a collection of bytes.
> ///
> /// Reads and writes on memory via `UnsafeBytes` are untyped operations that
> /// do no require binding the memory to a type. These operations are expressed
> /// in terms of `UInt8`, though the underlying memory is untyped.
>
> …
>
> You could go even further towards hinting this fact with a `typealias Byte = UInt8`, and use Byte throughout. But, I don’t know if that’s getting too excessive.
I don't think that's too excessive at all. I might even go further and say that we should call it "Untyped" instead of "Byte", to really drive home the point (many people see "byte" and think "8-bit int", which is merely a side effect of CPUs generally not having support for types *other* than ints and floats, rather than a reflection of the true "type" of the data).
- Dave Sweeris
More information about the swift-evolution
mailing list