3 ms·
That would require each argument be printable (i.e., has a function that prints its contents in a human-readable format), which is not always a given. Also, tr
by yongjik 5y ago
That would require each argument be printable (i.e., has a function that prints its contents in a human-readable format), which is not always a given. Also, trying to print an object may cause another exception. (Imagine what will happen if you have a linked list, and a printer function that follows the links and print all nodes, but now the list is circular.)
- zanecodes 5y agoThat'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.