[swift-evolution] [swift-evolution-announce] [Review #2] SE-0101: Reconfiguring sizeof and related functions into a unified MemoryLayout struct

David Owens II david at owensd.io
Wed Jul 13 00:19:16 CDT 2016


What is your evaluation of the proposal?
I’m not in favor of the majority of this proposal (I do support getting rid of the *Value versions of the functions). Of the motivations, I find this one to be the most awkward:

> Refactoring this proposal to use a single namespace increases discoverability, provides a single entry point for related operations, and enables future expansions without introducing further freestanding functions.

While technically storing stuff under a new type creates a level of indirection that we may refer to a namespace, it does so in a way that I’m not terribly convinced is even conceptually correct. A new MemoryLayout struct implies there is actually a type we are creating here, but that’s not the case: we are simply using the type as a hack to get a namespace because Swift lacks support for that notion. 

If we must have a struct to achieve this, than at the very least, can’t we move all of the generics onto the function call itself?

public struct MemoryLayout {
    public static func sizeof<T>(_ x: T.Type) -> Int { return Swift.sizeof(x) }
// ...
}

Further, I find this change to just make readability suffer. Here’s is a random snippet found from a GitHub search:

let data = NSData(bytes: &bytes, length:sizeof(CChar) * bytes.count)
let data = NSData(bytes: &bytes, length:MemoryLayout<CChar>.size * bytes.count)

That’s a lot more typing for what? 

let data = NSData(bytes: &bytes, length:MemoryLayout.sizeof(CChar) * bytes.count)

The above actually satisfies the concern, which seems to be primarily that the functions are top-level functions instead of namespaced.

Is the problem being addressed significant enough to warrant a change to Swift?
No. Like mentioned in the proposal, these are already low-use terms. As such, there is a much prior art for these to turn up search results easily for them and their concept apply across multiple languages.

Does this proposal fit well with the feel and direction of Swift?
No. The heart of the proposal seems to be a workaround for the lack of namespacing in Swift.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Yes, those languages have better readability around these terms.

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I’ve read the proposal, looked up code snippets, and tested my own implementation within playgrounds.

-David

> On Jul 12, 2016, at 4:53 PM, Chris Lattner <clattner at apple.com> wrote:
> 
> Hello Swift community,
> 
> The second review of "SE-0101: Reconfiguring sizeof and related functions into a unified MemoryLayout struct" begins now and runs through July 19. The proposal is available here:
> 
> 	https://github.com/apple/swift-evolution/blob/master/proposals/0101-standardizing-sizeof-naming.md
> 
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> 
> 	https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> or, if you would like to keep your feedback private, directly to the review manager.
> 
> What goes into a review?
> 
> The goal of the review process is to improve the proposal under review through constructive criticism and contribute to the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> 
> 	* What is your evaluation of the proposal?
> 	* Is the problem being addressed significant enough to warrant a change to Swift?
> 	* Does this proposal fit well with the feel and direction of Swift?
> 	* If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> 	* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> 
> More information about the Swift evolution process is available at
> 
> 	https://github.com/apple/swift-evolution/blob/master/process.md
> 
> Thank you,
> 
> -Chris Lattner
> Review Manager
> 
> 
> _______________________________________________
> swift-evolution-announce mailing list
> swift-evolution-announce at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution-announce

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160712/9da893f2/attachment.html>


More information about the swift-evolution mailing list