[swift-users] Why do collections use the debugDescription on their elements?

Ole Begemann ole at oleb.net
Thu Jan 5 10:53:16 CST 2017


> I wonder why the description method of collections use the debugDescription method to print their elements, and not the description method.

Dmitri Gribenko gave this reason in December 2015 [1]:

> 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.

[1]: 
https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000272.html



More information about the swift-users mailing list