[swift-evolution] [Pitch] Renaming sizeof, sizeofValue, strideof, strideofValue
Xiaodi Wu
xiaodi.wu at gmail.com
Thu Jun 2 00:05:57 CDT 2016
On Wed, Jun 1, 2016 at 11:55 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> On Wed, Jun 1, 2016 at 11:28 PM, Erica Sadun via swift-evolution <
> swift-evolution at swift.org> 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()
```
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.
* * *
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160602/56995bd7/attachment.html>
More information about the swift-evolution
mailing list