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

Dmitri Gribenko gribozavr at gmail.com
Fri Dec 11 16:47:13 CST 2015


On Fri, Dec 11, 2015 at 1:38 PM, Wojciech Czekalski via swift-dev <
swift-dev at swift.org> wrote:

> Hi,
>
> while I was working on this <https://github.com/apple/swift/pull/348> PR
> I encountered unexpected behavior from Array.description. It iterates
> over its items and calls debugDescription on them. I found it a bit
> unexpected thus my question here. Is it desired behavior? I would expect
> description and debugDescription call respective methods on the contents.
>

Array's description shouldn't be presented to the user in raw form, ever,
so the use case here is debugging.  Thus, it makes sense to present the
debug representation of the elements in both cases.  Consider an array of
strings:

var myArray = [ "", "", "" ]

If we used the regular description, then String(myArray) would be "[ , ,
]", which looks like a library bug.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151211/fc4e6123/attachment.html>


More information about the swift-dev mailing list