What is your preferred name for an extension funct...
# codingconventions
d
What is your preferred name for an extension function which is essentially a local version of 
.toString()
 but you can’t call it “toString” because it’s shadowed by 
Object#toString
?
e
It depends on why you are adding it. I usually call it
.toXxxString()
where
xxx
is the reason as to why it exists (debug, log, etc)
👍🏻 5
d
There was a bit longer discussion in another chat, and yes, most answers gravitate around "why". Here are few options: - if you own the code, consider changing the original
.toString()
, because why not?🙄 - use a synonym for
.toString()
(what @Shawn said), e.g.
.string()
or extension value
.string
. For immutable objects,
.asString()
is also an option. -
.toXxxString()
(what Roman said), e.g.
.toDebugString()
,
.toPrettyString()
- focus on a more abstract purpose rather than string, e.g.
.forDisplay()
,
.toDebugOutput()
,
.forDeveloperEyesOnly()
,
.forReport()