Dokumentacja

Zasady inżynierii oprogramowania w Pythonie

Adam Spannbauer

Machine Learning Engineer at Eastman

Dokumentacja w Pythonie

  • Komentarze
# Square the number x
  • Docstringi
    """Square the number x

    :param x: number to square
    :return: x squared

    >>> square(2)
    4
    """
Zasady inżynierii oprogramowania w Pythonie

Komentarze

# This is a valid comment
x = 2
y = 3  # This is also a valid comment
# You can't see me unless you look at the source code

# Hi future collaborators!!
Zasady inżynierii oprogramowania w Pythonie

Skuteczne komentarze

Komentowanie „co"

# Define people as 5
people = 5

# Multiply people by 3
people * 3

Komentowanie „dlaczego"

# There will be 5 people attending the party
people = 5

# We need 3 pieces of pizza per person
people * 3
Zasady inżynierii oprogramowania w Pythonie

Docstringi

def function(x):
    """High level description of function

    Additional details on function
Zasady inżynierii oprogramowania w Pythonie

Docstringi

def function(x):
    """High level description of function

    Additional details on function

    :param x: description of parameter x
    :return: description of return value

Przykładowa strona wygenerowana z docstringa pakietu Flask.

Zasady inżynierii oprogramowania w Pythonie

Docstringi

def function(x):
    """High level description of function

    Additional details on function

    :param x: description of parameter x
    :return: description of return value

    >>> # Example function usage
    Expected output of example function usage
    """
    # function code
Zasady inżynierii oprogramowania w Pythonie

Przykładowy docstring

def square(x):
    """Square the number x

    :param x: number to square
    :return: x squared

    >>> square(2)
    4
    """
    # `x * x` is faster than `x ** 2`
    # reference: https://stackoverflow.com/a/29055266/5731525
    return x * x
Zasady inżynierii oprogramowania w Pythonie

Wynik przykładowego docstringa

help(square)
square(x)
    Square the number x

    :param x: number to square
    :return: x squared

    >>> square(2)
    4
Zasady inżynierii oprogramowania w Pythonie

Czas na ćwiczenia!

Zasady inżynierii oprogramowania w Pythonie

Preparing Video For Download...