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

Do getters and setters lead to safer code?

In the video Object-Oriented Python, Design, Kenneth says that Python doesn't depend on getters and setters like in other languages. The examples have already shown how someone could set and access class attributes from outside the class: awesome.

But isn't this a little dangerous? Getters and setters are a pain in the you-know-what to write and maintain, but hiding the information away also keeps it safe. I guess I'm asking something philosophical: do getters and setters, facilitators of information hiding, lead to safer code that's less prone to breaking?

1 Answer

Steven Parker
Steven Parker
243,658 Points

I'd agree, but the "Pythonic" philosophy tends to be more open and relaxed than other languages. So the fact that it doesn't have really strict mechanisms for protection seems to be consistent with that philosophy.

Most languages have their own unique strengths and weaknesses. If code safety is the major focus of a project, Python might not be the best language to choose. But on the other hand, it's hard to beat if your main concern is rapid development.