Those seem like cogent distinctions, although the naming might need some juggling - `to_s` and `to_str` seem mentally interchangeable. Instead of `to_s`: maybe `to_display_str`, `to_display`, or even just `display`? Maybe `to_str`, could be something like `serialize` or `str_serialize`? I think the name `inspect` does a good job of communicating its intent (although I guess I might as well suggest `str_inspect` to match my other suggestions).
The ruby conventions are illuminating, but I’m not sure all three variants are necessary; something from
serialize is probably better for the
to_str variant’s use case of “a string from which the object can be recreated”.
I like the idea of having
Show be “a string for debug purposes” (the equivalent of ruby’s
inspect or python’s
to_string be “a string for display purposes”, with a default implementation using
I see a difference between
to_str. To me
serialize is a verb that requires a specifier: “serialize using JSON” or “serialize using YAML”.
serialize also means that some choiches have to be made in order to go from the internal representation to the serialized form. Last, I do not expect a serialization to be human-readable.
On the contrary,
to_str implies that the object was already string-like and human-readable and the conversion was very straightforward.
BTW, in Ruby,
to_s defaults to
to_str when it is implemented.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.