<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 1, 2016 at 7:00 PM, Dave Abrahams via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
on Thu Apr 28 2016, Xiaodi Wu <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
<br>
> We all know and love sizeof(), but given that it's different from its C<br>
> counterpart anyway, shouldn't these conform to Swift naming guidelines? In other<br>
> words, after SE-0006, shouldn't these names be as follows?<br>
><br>
> ```<br>
> size<T>(of: T.Type)<br>
> size<T>(ofValue: T)<br>
> stride<T>(of: T.Type)<br>
> stride<T>(ofValue: T)<br>
> align<T>(of: T.Type)<br>
> align<T>(ofValue: T)<br>
> ```<br>
><br>
> There are obvious issues with two different things named `stride`, but IMO<br>
> that's best addressed by renaming one of them; the real problem is that the word<br>
> stride is used in two different ways already. Thoughts?<br>
<br>
</div></div>These functions correspond to C and LLVM primitives and we consciously<br>
kept those names because they are terms of art.</blockquote><div><br></div><div>I recognize that this was the intention behind preserving the names as-is. The thought process behind proposing a renaming was as follows:</div><div><br></div><div>* The Swift counterpart to C `sizeof()` is `strideof(_:)`. Thus, although the *names* are treated as terms of art, not all of them are used to mean the art for which they are terms (if you will). To reinforce the separation between C primitives and these Swift functions, C `offsetof()` has no Swift counterpart.</div><div><br></div><div>* A survey of other languages suggests that, as terms of art, these names are not always treated as a single word but as a phrase, by which I mean that the preposition "of" can be subject to language-specific naming conventions. For example, in Rust you have `size_of()`, `size_of_val()`, etc.; in the .NET Framework, you have the `Marshal.SizeOf()` method; and even in LLVM you apparently have (and this is based just on googling--my level of familiarity with LLVM is low to nonexistent) struct `AlignOf<T>`.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't know that<br>
<br>
size(of: T.self)<br>
<br>
is particularly descriptive usage, and if we were going to change them<br>
so they didn't look like sizeof, strideof, alignof I'd want to make them<br>
far more descriptive. E.g.<br>
<br>
memoryFootprint(Int.self)<br>
<br>
or<br>
<br>
bytesRequiredForStorage(Int.self)<br>
standardByteAlignment(Int.self)<br>
bytesBetweenArrayElements(Int.self)<br>
<br>
etc.<br></blockquote><div><br></div><div>To my mind, `size(of:)` is not moving away from using a term of art but rather following existing precedent in conforming use of the preposition to language-specific conventions. Like you, I would be hesitant to suggest moving away from these terms of art altogether. I do think, though, that moving the preposition has the bonus of visually suggesting however subtly that `size(of:)` might have a Swift-specific twist that makes it not a drop-in equivalent for C `sizeof()`.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Dave<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div></div>