4 ms·
> I can't tell you how many time in my code or in others', a .ToString() was expected to do one thing (pretty-print, for example) I'd expect this to turn the o
by dmix 7y ago
> I can't tell you how many time in my code or in others', a .ToString() was expected to do one thing (pretty-print, for example)
I'd expect this to turn the object into a String.
- thelazydogsback 7y agoSure. What kind of string? For debugging? If so, is a recursive? For output to a log? For output to a widget in a UI? To a string suitable for a report? What encoding? What language?
- earenndil 7y agoWhy not add an expectation, then, for what kind of string it is? You just have to have one. E.G. perl has .perl, which has the constraint that, for any obj, it should be that obj == (EVAL obj.perl). It doesn't matter what that is, as long as you agree on it. Having objects that know how to print themselves isn't intrinsically problematic.
- thelazydogsback 7y agoThat is serialization, which is one purpose for converting to a string. Dynamic languages already tend to be able to print objects in a way that's meaningful -- such as most REPL-based languages that have a reader (or eval) and a printer. As do ML-derived languages the print in constructor format, but they tend not to have readers or eval. Having it called .perl in this case is already a step in the right direction from toString, as you know what its for.
- ludamad 7y agoThat's almost comically underspecified. One big concern that comes to mind, is the string a complete view of the object (and thus suitable for serialization) or not? Or is it more succinct and suitable for a print statement?
- dmix 7y agoYes, I get the Java stuff, I was being sarcastic because it totally missed the context it was built with, in favour of some generalist mainstream adoption critique which misses the point. Have you seen the homepage? The Potion Pledge "everything is an object" bit was a good hint.