Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects Harnessing the Power of Objects Incrementing and Decrementing

Ranvir Sahota
Ranvir Sahota
9,844 Points

Why declare wasDispensed?

Could we have not achieved the same results with this code? public boolean dispense() { if (!isEmpty()) { pezCount--; return true; } return false; }

You could achieve the same result, but it would not be as readable. It's very important for your code to be easy to read and follow.

Whether you are working on a team or simply returning to your own code after a period of time. If the code is not easy to follow, it will not be easy to build upon or improve.

Ranvir Sahota
Ranvir Sahota
9,844 Points

Thanks AJ Longstreet I wasn't taking readabilty into account. If you put your answer into a post ill give it best answer and upvote

1 Answer

You could achieve the same result, but it would not be as readable. It's very important for your code to be easy to read and follow.

Whether you are working on a team or simply returning to your own code after a period of time. If the code is not easy to follow, it will not be easy to build upon or improve.