![A stick figure smiling](/images/welcome.jpg)
Here's a preview from my zine, The Pocket Guide to Debugging! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!
![Image of a comic. To read the full HTML alt text, click "read the transcript".](/images/uploads/the-pocket-guide-to-debugging-wizard-zines-55.png)
read the transcript!
Sometimes you print out an object, and it just prints the class name and reference ID, like this:
MyObject<#18238120323>
Illustration of a frowning stick figure with curly hair.
person (thinking): “ugh, thanks, very helpful… “
Implementing a custom string representation for a class you’re often printing out can save a LOT of time. The name of the method you need to implement is:
- Python: .__str__
- Ruby: .to_s
- JavaScript: .toString
- Java: .toString
- Go: String()
Also, pretty-printing libraries (like pprint
in Python or awesome_print
in Ruby) are great for printing out arrays/hashmaps.
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!