[swift-evolution] [Review] SE-0101: Rename sizeof and related functions to comply with API Guidelines

Dave Abrahams dabrahams at apple.com
Wed Jun 29 01:54:24 CDT 2016


on Tue Jun 28 2016, Hooman Mehr <swift-evolution at swift.org> wrote:

> How about we get rid of dynamicType by adding instance level properties as well:
>
> public struct MemoryLayout<T> {
>
>     public static var size: Int { return sizeof(T) }
>     public static var interval: Int { return strideof(T) }
>     public static var alignment: Int { return alignof(T) }
>
>     public var size: Int { return sizeof(T) }
>     public var interval: Int { return strideof(T) }
>     public var alignment: Int { return alignof(T) }
>
>     init(_ : @autoclosure () -> T) {}
> }
>
> print(MemoryLayout<Int>.size) // 8
> print(MemoryLayout<Int>.interval) // 8
> print(MemoryLayout<Int>.alignment) // 8
>
> let x = 8
>
> print(MemoryLayout(x).size) // 8
> print(MemoryLayout(x).interval) // 8
> print(MemoryLayout(x).alignment) // 8

My worry is that people will write 

  MemoryLayout(Int.self).size 

when they mean

  MemoryLayout<Int>.size 
     
(often because for some reason they don't like angle brackets).

I prefer to make the uncommon case much harder to write.

>
>> On Jun 28, 2016, at 5:08 PM, Dave Abrahams via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> 
>> on Tue Jun 28 2016, Brandon Knope <bknope-AT-me.com> wrote:
>> 
>>> Isn't dynamicType possibly changing soon to a method?
>> 
>> A free function, I think.
>> 
>>> This could look much different
>> 
>> Yes, It will be uglier.  But this very uncommon case is not important to
>> optimize for beauty.
>> 
>> -- 
>> Dave
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>

-- 
Dave



More information about the swift-evolution mailing list