[swift-users] String initializers and developer ergonomics
Chris Lattner
clattner at apple.com
Mon May 9 22:02:36 CDT 2016
On May 9, 2016, at 10:25 AM, Joe Groff via swift-users <swift-users at swift.org> wrote:
>> This seems like a tricky gotcha for developers who aren't extremely familiar with both the String and reflection APIs. His code looked reasonable at a first glance and I didn't suspect anything was wrong until I profiled it. Even so, I only made the connection because I recognized the name of the standard library function from poking around inside the source files.
>>
>> What do other people think? Is this something worth worrying about, or is it so rare that it shouldn't matter? Also, any suggestions as to how that code sample might be improved would be appreciated - my naive first attempt wasn't any better.
>
> This definitely strikes me as a problem. The String<T>(_:) constructor is very easy to call by accident if you're trying to hit another unlabeled initializer. It also strikes me as not particularly "value-preserving", since stringifying many types loses information. Perhaps we should propose giving it a label, String(printing:) maybe?
I agree, +1.
-Chris
More information about the swift-users
mailing list