[swift-evolution] [Review] SE-0089: Renaming String.init<T>(_: T)

Karl Wagner razielim at gmail.com
Wed May 25 16:56:20 CDT 2016


What is so bad about the global function idea?

reflect(_:Any)->String

It’s invoking the reflection APIs, doing a bunch of things you could do yourself with Mirror, and returning a String.

I know we don’t have many global functions, but this seems like a reasonable place for one.

This isn’t Objective-C; we have namespaces. You can still create another function with that same signature, and refer to the global one with Swift.reflect().

Karl

> On 22 May 2016, at 20:19, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> on Fri May 20 2016, Kevin Ballard <swift-evolution at swift.org> wrote:
> 
>> On Fri, May 20, 2016, at 05:14 PM, Dave Abrahams via swift-evolution wrote:
>>> 
>>> on Fri May 20 2016, Kevin Ballard <swift-evolution at swift.org> wrote:
>>> 
>>>> On Tue, May 17, 2016, at 08:32 PM, Chris Lattner via swift-evolution wrote:
>>>>> 	* What is your evaluation of the proposal?
>> 
>>>> 
>>>> I'm a little nervous about this change, because converting things to
>>>> strings is a fairly basic operation and it should be immediately
>>>> obvious how to do that. That said, the described issues are pretty
>>>> bad, and I know I've had to carefully triple-check sometimes to make
>>>> sure I was calling the right initializer. So I'm +1 on the idea.
>>>> 
>>>> That said, I don't like the name String(printing:). As others have
>>>> pointed out, it sounds like this is related to print(), but this
>>>> initializer does not actually print anything, it just converts any
>>>> value into a string. I also don't like String(describing:) because
>>>> it's too long. This initializer should be easier to call than
>>>> String(reflecting:). Also, in my experience this initializer is
>>>> particularly useful with code of the form `someOpt.map(String.init)`,
>>>> and saying `someOpt.map(String.init(describing:))` is annoyingly long.
>>>> 
>>>> Given this, I'd like to suggest the simpler `String(from:)`. It's
>>>> short and generic, and it makes sense as it creates a String from any
>>>> value.
>>> 
>>> Not too bad.  I could live with it.
>> 
>> 😀
>> 
>>>> I'm also not a fan of Dave's suggestion of removing this initializer
>>>> entirely in favor of "\(foo)".  This feels weird, and it also can't be
>>>> turned into a first-class function value.
>>> 
>>>  { "\($0)" }
>>> 
>>> ?
>> 
>> Good point. I think what I intended to express was you cannot refer to
>> this operation by name anymore. Maybe not a big deal, but it feels
>> weird.
> 
> Makes sense.
> 
> -- 
> -Dave
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list