swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 429 forks source link

Update lesson 18-style to follow google style guide for function docstrings #359

Open mikewolfe opened 5 years ago

mikewolfe commented 5 years ago

In the Programming Style lesson the google style guide for writing function docstrings is mentioned, but the style of the example docstrings in the lesson do not follow the google style guide. It may be worth introducing users to the idea of a google style function docstring like the example in the google style guide:

def fetch_bigtable_rows(big_table, keys, other_silly_variable=None):
    """Fetches rows from a Bigtable.

    Retrieves rows pertaining to the given keys from the Table instance
    represented by big_table.  Silly things may happen if
    other_silly_variable is not None.

    Args:
        big_table: An open Bigtable Table instance.
        keys: A sequence of strings representing the key of each table row
            to fetch.
        other_silly_variable: Another optional variable, that has a much
            longer name than the other args, and which does nothing.

    Returns:
        A dict mapping keys to the corresponding table row data
        fetched. Each row is represented as a tuple of strings. For
        example:

        {'Serak': ('Rigel VII', 'Preparer'),
         'Zim': ('Irk', 'Invader'),
         'Lrrr': ('Omicron Persei 8', 'Emperor')}

        If a key from the keys argument is missing from the dictionary,
        then that row was not found in the table.

    Raises:
        IOError: An error occurred accessing the bigtable.Table object.
    """

This would force new users to think about what a function does, what inputs it takes in, and what output it returns, thereby encouraging good style practices and reinforcing the learning goals for functions at the same time.

martinosorb commented 1 year ago

I think this is a good idea. It would give the learners a better idea of what docstrings are useful for.

@mikewolfe if you're still there after all these years (sorry, I'm going through the backlog of issues), would you be interested in submitting a PR?