[swift-evolution] Trial balloon: conforming sizeof, sizeofValue, etc. to naming guidelines

Xiaodi Wu xiaodi.wu at gmail.com
Fri Apr 29 15:04:35 CDT 2016


On Thu, Apr 28, 2016 at 3:55 PM, Josh Parmenter via swift-evolution <
swift-evolution at swift.org> wrote:

> I think this is a nice suggestion as well.
> Best,
> Josh
>
> On Apr 28, 2016, at 1:52 PM, Joe Groff via swift-evolution <
> swift-evolution at swift.org<mailto:swift-evolution at swift.org>> wrote:
>
>
> On Apr 28, 2016, at 11:44 AM, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org<mailto:swift-evolution at swift.org>> wrote:
>
> We all know and love sizeof(), but given that it's different from its C
> counterpart anyway, shouldn't these conform to Swift naming guidelines? In
> other words, after SE-0006, shouldn't these names be as follows?
>
> ```
> size<T>(of: T.Type)
> size<T>(ofValue: T)
> stride<T>(of: T.Type)
> stride<T>(ofValue: T)
> align<T>(of: T.Type)
> align<T>(ofValue: T)
> ```
>
> There are obvious issues with two different things named `stride`, but IMO
> that's best addressed by renaming one of them; the real problem is that the
> word stride is used in two different ways already. Thoughts?
>
> Seems reasonable to me.
>


Well, glad that it's uncontroversial. Here's a draft of a short proposal
then. Comments welcome:

Rename sizeof(_:) and related functions to follow API naming guidelines

   - Proposal: SE-NNNN
   <https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md>
   - Author(s): Xiaodi Wu <https://github.com/xwu>
   - Status: Awaiting review
   <https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#rationale>
   - Review manager: TBD

<https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#introduction>
Introduction

With SE-0006
<https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md>,
Standard Library APIs have been renamed to follow a set of naming
guidelines. However, sizeof(_:) and related functions do not follow these
guidelines.

Since sizeof(_:) behaves differently in any case from sizeof() in other
C-family languages, it makes sense to conform these functions to Swift
naming guidelines.

Swift-evolution thread: [link goes here]
<https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#proposed-solution>Proposed
solution

The proposed solution is to rename sizeof(_:) and related functions as
follows:

func size<T>(of: T.Type)   // currently: sizeof<T>(_: T.Type)func
size<T>(ofValue: T)   // currently: sizeofValue<T>(_: T)func
stride<T>(of: T.Type) // currently: strideof<T>(_: T.Type)func
stride<T>(ofValue: T) // currently: strideofValue<T>(_: T)func
align<T>(of: T.Type)  // currently: alignof<T>(_: T.Type)func
align<T>(ofValue: T)  // currently: alignofValue<T>(_: T)

<https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#detailed-design>Detailed
design

With the renaming proposed above, stride(of:) will appear to be related to
stride(from:to:by:). This conflict arises from a pre-existing issue;
namely, the term "stride" is used to mean two different things. Although
moving the preposition only highlights the issue, one possible resolution
is to rename strideof(_:) to strideSize(of:) and strideofValue(_:) to
strideSize(ofValue:).
<https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#impact-on-existing-code>Impact
on existing code

The proposed changes are as source-breaking for current code as the set of
changes implemented for SE-0006. During implementation, previous names can
be annotated as unavailable symbols to allow the proper Fix-Its to be
emitted by the compiler.
<https://github.com/xwu/swift-evolution/blob/master/proposals/NNNN-rename-sizeof.md#alternatives-considered>Alternatives
considered
The alternative is to maintain current function names.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160429/54c7a5b0/attachment.html>


More information about the swift-evolution mailing list