<div dir="ltr">Well, I mean, it's not as though you invented them just for Swift. It's possible to evaluate sizeof an instance in C, C++, C#, D, Python, Rust... Removing this facility from Swift is a whole nother discussion from renaming.<div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 2, 2016 at 3:11 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"><span class=""><br>
on Mon May 02 2016, Xiaodi Wu <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
<br>
> I like it, but how do you accommodate sizeofValue, etc?<br>
<br>
</span>IMO you don't.  I added those years ago on a whim, when whims were what<br>
we had to guide development.  I'm unconvinced they add value to Swift.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
><br>
> On Mon, May 2, 2016 at 11:46 Dave Abrahams<br>
> <<a href="mailto:dabrahams@apple.com">dabrahams@apple.com</a>> wrote:<br>
><br>
>     on Sun May 01 2016, Xiaodi Wu <<a href="http://xiaodi.wu-AT-gmail.com" rel="noreferrer" target="_blank">xiaodi.wu-AT-gmail.com</a>> wrote:<br>
><br>
>     > It's a bad habit of mine, I guess, to err on the side of suggesting<br>
>     conservative<br>
>     > changes on the assumption that it'll be maximally acceptable. If there's<br>
>     > appetite for a more serious renaming, and as you say these are considered<br>
>     > relatively rarely used, then it's a world of possibility!<br>
>     ><br>
>     > We could do as Shawn suggested and follow precedent in some other<br>
>     languages by<br>
>     > moving these functions out of the global scope. Perhaps these will meet<br>
>     with<br>
>     > some satisfaction:<br>
>     ><br>
>     > ```<br>
>     > Memory.footprint(of:)<br>
>     > Memory.alignment(of:)<br>
>     > Memory.spacing(of:)<br>
>     > ```<br>
><br>
>     I'd rather have<br>
><br>
>     MemoryLayout<T>.size<br>
>     MemoryLayout<T>.alignment<br>
>     MemoryLayout<T>.spacing<br>
><br>
>     -Dave<br>
><br>
>     > On Sun, May 1, 2016 at 21:41 Dave Abrahams via swift-evolution<br>
>     > <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>     ><br>
>     > on Sun May 01 2016, Xiaodi Wu<br>
>     <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>     ><br>
>     > > On Sun, May 1, 2016 at 7:00 PM, Dave Abrahams via swift-evolution<br>
>     > > <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
>     > ><br>
>     > > on Thu Apr 28 2016, Xiaodi Wu<br>
>     > > <<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<br>
>     C<br>
>     > > > counterpart anyway, shouldn't these conform to Swift naming<br>
>     guidelines?<br>
>     > In<br>
>     > > 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<br>
>     > IMO<br>
>     > > > that's best addressed by renaming one of them; the real problem is<br>
>     that<br>
>     > > the word<br>
>     > > > stride is used in two different ways already. Thoughts?<br>
>     > ><br>
>     > > These functions correspond to C and LLVM primitives and we consciously<br>
>     > > kept those names because they are terms of art.<br>
>     > ><br>
>     > > I recognize that this was the intention behind preserving the names<br>
>     as-is.<br>
>     > The<br>
>     > > thought process behind proposing a renaming was as follows:<br>
>     > ><br>
>     > > * The Swift counterpart to C `sizeof()` is `strideof(_:)`. Thus,<br>
>     although<br>
>     > the<br>
>     > > *names* are treated as terms of art, not all of them are used to mean<br>
>     the<br>
>     > art<br>
>     > > for which they are terms (if you will).<br>
>     ><br>
>     > The specific meaning of sizeof in Swift comes from either LLVM or from<br>
>     > SIL, IIRC. It predates me, but it's supposed to correspond to what the<br>
>     > IRGen level of the compiler calls “sizeof.”<br>
>     ><br>
>     > > To reinforce the separation between C primitives and these Swift<br>
>     > > functions, C `offsetof()` has no Swift counterpart.<br>
>     ><br>
>     > Yes, that's part of the reason I'd very much like to choose more<br>
>     > descriptive names if we are going to move away from the current<br>
>     > spellings. moving the parenthesis is a pretty weak cue that this thing<br>
>     > might be slightly different.<br>
>     ><br>
>     > > * A survey of other languages suggests that, as terms of art, these<br>
>     names<br>
>     > are<br>
>     > > not always treated as a single word but as a phrase, by which I mean<br>
>     that<br>
>     > the<br>
>     > > preposition "of" can be subject to language-specific naming conventions.<br>
>     > For<br>
>     > > example, in Rust you have `size_of()`, `size_of_val()`, etc.; in the .<br>
>     NET<br>
>     > > Framework, you have the `Marshal.SizeOf()` method; and even in LLVM you<br>
>     > > apparently have (and this is based just on googling--my level of<br>
>     > familiarity<br>
>     > > with LLVM is low to nonexistent) struct `AlignOf<T>`.<br>
>     > ><br>
>     > > 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>
>     > ><br>
>     > > To my mind, `size(of:)` is not moving away from using a term of art but<br>
>     > rather<br>
>     > > following existing precedent in conforming use of the preposition to<br>
>     > > language-specific conventions.<br>
>     ><br>
>     > The same argument could be made for “mapped” and “reduced.”<br>
>     ><br>
>     > > Like you, I would be hesitant to suggest moving away from these terms<br>
>     > > of art altogether.<br>
>     ><br>
>     > You misunderstand me. I'm not hesitant about that at all. What I<br>
>     > dislike is the idea of being close-to-but-not-quite-the-same as the<br>
>     > source terms to which they correspond. The original terms are not<br>
>     > great, and these facilities are seldom used. They can afford to be<br>
>     > longer and more descriptive.<br>
>     ><br>
>     > > I do think, though, that moving the preposition has the bonus of<br>
>     > > visually suggesting however subtly that `size(of:) ` might have a<br>
>     > > Swift-specific twist that makes it not a drop-in equivalent for C<br>
>     > > `sizeof()`.<br>
>     ><br>
>     > I don't think subtlety is a virtue in this case.<br>
>     ><br>
>     > --<br>
>     > Dave<br>
>     ><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>
>     ><br>
><br>
>     --<br>
>     Dave<br>
><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>
<br>
--<br>
Dave<br>
<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>