DEV Community


The importance of being earnest about your return values

das11706 profile image Daniel Suarez ・2 min read

I would like to write about return values. And upon that subject the simple matter of properly confirming your return values. Sounds simple enough, but as a new programmer this idea of return values has not yet been firmly planted in my head.

I was going to work on my first major project, scraping a website and creating a CLI. It didn't take long to figure out what I wanted to do. The numbers on recyclables have always confounded me. I thought I might scrape a website with information on recyclables and offer some simple and clear facts on plastics. I thought this might be helpful to many.

I chose my classes composed of Plastic, Fact, CLI, and, Scraper. These seemed like good and logical classes for this scrape.
I worked on my code for some time and things slowing evolved and became more focused. I used pry often and everywhere to check and confirm my code but here is where I also struggled for some time. As I looked upon the return values provided by pry, all the information that I needed was on my screen. Yet my code was not working correctly. I ran pry many times and each time it provided the perfect answer. Yet my code would stall. I was perplexed.

I finally realized by an inadvertent scroll of my screen that I was not properly checking the entire return value but just a part of it. I was only looking at the return value for an instance variable. Had I looked closer I would have discovered it was the entire object being returned and why my code was not working. I laughed at my newbie mistake but it was also a good hard lesson to learn on the importance of being earnest about your return values.

Discussion (0)

Editor guide