4 ms·
That's a good point. I would also like very much if languages included a sensible and useful default implementation of toString() or the equivalent for all type
by zanecodes 5y ago
That's a good point. I would also like very much if languages included a sensible and useful default implementation of toString() or the equivalent for all types (e.g. print all the object's private & public property names & values, recursively, stopping if cycles are found).
Of course, this is probably only remotely feasible in languages that can guarantee that toString() won't have any side effects.
- gizmo686 5y agoYou need "side effects" to include memory allocation, seg faults, and "significant" amount of computation time (including never terminating). Worse, you need these properties when the program is known to be in an error state. For a general purpose programming language this means that your toString cannot be a normal function.
- zanecodes 5y agoAlso good points, I suppose the printing mechanism couldn't use the type's implementation of toString() and would instead have to use an implementation built into the runtime. Still, even being able to see just the raw bytes would be better than nothing in a lot of cases.