Stream: ideas

Topic: ✔ to_str


view this post on Zulip nandi (Dec 30 2025 at 16:23):

Recently submitted an issue regarding to_str method on builtin types. The feedback I got was that we have Str.inspect at home. The reason I wanted to_str is that it's hard to chain inspect because it's on Str type rather than the type of the type I'm actually using.

view this post on Zulip Anton (Dec 30 2025 at 16:27):

That's a valid point! @Richard Feldman is probably the person who is most aware of all the trade-offs here.

view this post on Zulip Richard Feldman (Dec 30 2025 at 18:43):

you can do ->Str.inspect to chain it!

view this post on Zulip nandi (Dec 30 2025 at 18:43):

TIL

view this post on Zulip Notification Bot (Dec 30 2025 at 18:44):

nandi has marked this topic as resolved.

view this post on Zulip Anton (Dec 30 2025 at 18:59):

Richard Feldman said:

you can do ->Str.inspect to chain it!

Perhaps .to_str would be worth it because it is easier to discover?

view this post on Zulip Richard Feldman (Dec 30 2025 at 19:11):

I should probably write about this somewhere, but philosophically the idea behind this design is:

view this post on Zulip Richard Feldman (Dec 30 2025 at 19:12):

which is how you get things like end users seeing null or undefined rendered to them :sweat_smile:

view this post on Zulip Richard Feldman (Dec 30 2025 at 19:13):

Try shouldn't have a "display to end users" method, but it should have a "turn into a string for debugging/logging purposes"

view this post on Zulip Richard Feldman (Dec 30 2025 at 19:14):

and if it had to_str, it would be easy for end users to accidentally see Ok displayed to them

view this post on Zulip Notification Bot (Dec 30 2025 at 21:46):

nandi has marked this topic as unresolved.

view this post on Zulip Notification Bot (Dec 30 2025 at 21:52):

nandi has marked this topic as resolved.


Last updated: Jun 16 2026 at 16:19 UTC