[swift-dev] [stdlib] Array.description calls debugDescription on its contents

Dave Abrahams dabrahams at apple.com
Mon Dec 14 01:08:56 CST 2015


> On Dec 13, 2015, at 12:43 PM, Wojciech Czekalski <wczekalski at me.com> wrote:
> 
> I agree with Brent that offering description on Arrays where it "shouldn't be presented to the user in raw form, ever, so the use case here is debugging”  is misleading.

I think it's a bit too absolute—there are a few applications where users could interact with the raw form of an array but these are mostly programming tools ;-).  I don't, however see how Dmitri's statement is in any way misleading.

> Is there any specific reason for them to offer it?

Who is "them" and what is "it?"

> Also, there is a slightly difference in representation of description and debugDescription for ContiguousArray and ArraySlice. If the motivation behind it is unclear it might be worth to remove either the difference in implementation or the conformance to CustomStringConvertible altogether.

Removing the conformance would make their printed representation useless and/or needlessly verbose depending on how you did it (try it yourself).

Dmitri's example is the driving use-case: when you print a string you want the literal contents, but when you print an array of strings you want the strings quoted, and to get the quoted representation of the elements when they are strings you need String(reflecting: arrayElement), not String(arrayElement).

> 
> -Wojtek
> 
>> Wiadomość napisana przez Dave Abrahams via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> w dniu 12.12.2015, o godz. 21:41:
>> 
>> 
>> 
>> Sent from my moss-covered three-handled family gradunza
>> 
>>> On Dec 12, 2015, at 9:09 AM, Brent Royal-Gordon via swift-dev <swift-dev at swift.org <mailto:swift-dev at swift.org>> wrote:
>>> 
>>> It would similarly be nice if String.init(_: Any) were instead String.init(_: CustomStringConvertible), and passing something to it that wasn’t convertible was an error.
>> 
>> Why would that be nice?  It is an explicit goal that every type can be represented as a string, whatever its conformance a, FWIW
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev at swift.org <mailto:swift-dev at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-dev
> 

-Dave



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151213/1a2dc041/attachment.html>


More information about the swift-dev mailing list