[swift-evolution] Renaming bitPattern and truncatingBitPattern

Dave Abrahams dabrahams at apple.com
Tue Feb 16 16:11:29 CST 2016


on Tue Feb 16 2016, David Turnbull <dturnbull-AT-gmail.com> wrote:

> I propose upgrading bit-casting labels to match the new API design
> guidelines. Here's what we have today:
>
> UInt8(bitPattern: someInt8)
> Uint8(truncatingBitPattern: someBiggerInt)
>
> "Bit pattern" has the needless word "pattern" while not reading well due to
> the lack of a verb or preposition. Simply "bits" will not be confused with
> something else in this context. "Truncating" is the present participle
> which is confusing.
>
> I like:
> UInt8(fromBits: someInt8)
> Uint8(truncateBits: someBiggerInt)

I don't think any of these are as obvious as the current names.  “bitPattern”
says, “give the result this bit pattern,” rather than simply “use these
bits (somehow).”  Likewise you could ask, “in what way are these bits
being truncated?”

These names are long, but IMO the clarity is worth it considering that
they're comparitively-rarely used.

-- 
-Dave


More information about the swift-evolution mailing list