Skip to content

hangman: Wondering why remaining_guesses vs get_status() #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
petertseng opened this issue Sep 9, 2019 · 3 comments
Closed

hangman: Wondering why remaining_guesses vs get_status() #1910

petertseng opened this issue Sep 9, 2019 · 3 comments

Comments

@petertseng
Copy link
Member

petertseng commented Sep 9, 2019

Just curious about https://github.com/exercism/python/blob/master/exercises/hangman/hangman_test.py - remaining_guesses is accessed directly (implying it is either a property or an instance variable) whereas there is a get_status() and get_masked_word(), getter instance methods.

Since I am not very familiar with Python conventions I don't have a good sense of when someone should use property vs getter instance method. Any explanation available for this exercise as to why the respective choices were taken? Thank you.

@cmccandless
Copy link
Contributor

It wasn't specifically called out in the implementing PR (#1690) one way or the other.

If @junming403 is available for comment, that would be the only way to gain more insight.

@petertseng
Copy link
Member Author

Since that is the course of action and this issue does not appear to need maintainer action, let me close it to get it out of the track's issue queue. Explanations are still welcomed of course even after it is closed.

@petertseng
Copy link
Member Author

I turned to online style guides to answer the question in the issue, and found http://google.github.io/styleguide/pyguide.html#315-access-control

If an accessor function would be trivial, you should use public variables instead of accessor functions to avoid the extra cost of function calls in Python. When more functionality is added you can use property to keep the syntax consistent.

On the other hand, if access is more complex, or the cost of accessing the variable is significant, you should use function calls (following the Naming guidelines) such as get_foo() and set_foo().

Now I understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants