DEV Community

Daniel Suarez
Daniel Suarez

Posted on

The importance of being earnest about your return values

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.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more