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 repr), and to_string be âa string for display purposesâ, with a default implementation using Show.
I see a difference between serialize and 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.