xwu
(Xiaodi Wu)
July 23, 2025, 10:05pm
25
The steering group previously considered the matter as part of that prior review. As I reported out in the decision notes, the conclusion of the group was:
A central point of discussion was whether the conformance in question ought to be to CustomDebugStringConvertible rather than (and not in addition to) CustomStringConvertible. This group was asked to weigh in on what these protocols are "for."
There was agreement among the group with the simple explanation that debugDescription is the most appropriate API to provide a textual representation that is specifically "for" debugging.
While it's true that, where a standard library type implements both description and debugDescription, the latter often adds or removes punctuation so as to be more suitable for structured display, it's not the formatting details which alone account for the difference between the two APIs. Instead, the group was inclined to agree with reviewer feedback that conformance to CustomDebugStringConvertible conveys the intended use of the corresponding textual representation—namely, that it is oriented specifically towards debugging, and no attempt should be made to parse, convert, or otherwise manipulate the output.
By contrast, a value's description could be suitable for more general use. In this case, for example, it's conceivable that one could have a textual representation for string indices that'd be useful for someone learning about Unicode and who's totally unfamiliar with the String.Index type or even Swift at all. The representation proposed here is explicitly not that.
3 Likes