Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 26,972 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,342 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!