Skip to content

hangman: Wondering why remaining_guesses vs get_status() #1910

Closed

Description

@petertseng

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.

Activity

  1. cmccandless commented on Sep 9, 2019

    @cmccandless
    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.

  2. petertseng commented on Sep 10, 2019

    @petertseng
    MemberAuthor

    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.

  3. petertseng commented on Sep 10, 2019

    @petertseng
    MemberAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions