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

Python Python Basics All Together Now Cleaner Code Through Refactoring

No arguments needed for function calculate_price

I wrote a program where there was no need of an argument to be passed in function. IT would work exactly the same. Then, why are we passing an argument here.

3 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Good observation! One of the things that I enjoy about programming is there are so many right ways to do things, not just one.

The video is setting you up to learn the concept of parameter passing. You will need to master this design pattern.

In simple programs, you can make the choice to pass parameters in the global scope. But as your programs become more complex, or you are working on a programming team where your functions are part of a library, it is good practice to use parameter passing and good naming conventions to avoid name-space conflicts as well as abstraction.

There are many reasons to refactor code such as to make it logically clearer, fit more use cases, more modular/portable, or more efficient. Using well-named arguments will make refactoring easier.

Sean M
Sean M
7,344 Points

From my understanding, using functions in python or using methods in java can help reuse code in the program so you don't have to repeat yourself.

And if you need to change the formula or the variables used, you can just change the function/method, instead of searching through the entire program for the code you want to edit.

Cheers,

I get it now! Thanks for clearing my doubt, Sir!