on Wed Jun 01 2016, Xiaodi Wu <[email protected]> wrote:

> On Wed, Jun 1, 2016 at 11:55 PM, Xiaodi Wu <[email protected]> wrote:
>
>  On Wed, Jun 1, 2016 at 11:28 PM, Erica Sadun via swift-evolution 
> <[email protected]>
>  wrote:
>
>  Upon accepting SE-0098, the core team renamed the proposed stdlib function 
> from dynamicType() to type(of:). They write, "The
>  core team recognizes that this means that we should probably resyntax the 
> existing sizeof/strideof functions, but that should be
>  a follow-on discussion."
>
>  Follow on discussion started. Have at it.
>
>  See: http://thread.gmane.org/gmane.comp.lang.swift.evolution/15830
>
> To summarize the previous discussion:
>
> 1. Per Joe Groff, although sizeof() and friends are treated as terms-of-art, 
> these names were lifted straight from C and do not correspond to
> anything named "sizeof" in LLVM.
>
> 2. There are issues with using a name such as stride(of:), because 
> stride(...) already means something else in the stdlib; moreover, size(of:) 
> isn't
> the best name for something that doesn't do what its C namesake does; 
> therefore, larger changes to the naming were suggested.
>
> 2. Dave A. and others expressed the opinion that these should probably not be 
> global functions; his preference was for:
>
> ```
> MemoryLayout<T>.size // currently sizeof()
> MemoryLayout<T>.spacing // currently strideof()
> MemoryLayout<T>.alignment // currently alignof()
> ```

I'd also be willing to see memoryLayout(T.self).size, if pressed.

> 3. Dave A. proposed that sizeofValue(), strideofValue(), and
> alignofValue() are better off removed altogether. I don't know if
> people are going to be happy about this idea.

I would be happy to hear from people about their use-cases that become
utterly unreadable when 

  sizeofValue(x)

is replaced by 

  MemoryLayout<x.Self>.size

or

  memoryLayout(type(of: x)).size

But if we don't have strong evidence that such use-cases exist, I am
strongly biased toward removing those functions.  These incredibly
low-level facilities are seldom used, even within the standard library.
It would take a very strong argument to convince me that the exposed API
should be broader than absolutely necessary in this area.

> * * *
>
> If we take inspiration from type(of:), then it's actually sizeofValue(), 
> etc., that should be renamed size(of:), etc. Also, a fun tidbit is that what's
> currently called sizeof(), etc.--the ones that take types rather than 
> values--are actually not very good candidates for having parameter labels,
> because it's OK to write `sizeof(Int)`, but one must currently write 
> `size(of: Int.self)` when the function has a label.
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
>

-- 
-Dave

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to