Why worry about "reading"?
As we already discussed:
Categories of readability/comprehension/usability
Categories of readability/comprehension/usability
Lets go trough some things from each
Some considerations
def f(x, y): ...
# vs
def true_anomaly(mean_anomaly, eccentricity): ...
class AbstractInterruptibleBatchPreparedStatementSetter: ...
# vs (with some re-design)
class StatementSetter: ...
def gmf(zx, zr): ...
# vs
def generalized_match_function(
received_signal,
transmitted_signal,
): ...
v[1:-1, 1:-1] = (vn[1:-1, 1:-1] - dt / dx * un[1:-1, 1:-1] * (vn[1:-1, 1:-1] - vn[1:-1, 0:-2]) - dt / dy * vn[1:-1, 1:-1] * (vn[1:-1, 1:-1] - vn[0:-2, 1:-1]) + nu * dt / dx**2 * (vn[1:-1, 2:] - 2 * vn[1:-1, 1:-1] + vn[1:-1, 0:-2]) + nu * dt / dy**2 * (vn[2:, 1:-1] - 2 * vn[1:-1, 1:-1] + vn[0:-2, 1:-1]))
# vs
v[1:-1, 1:-1] = (
vn[1:-1, 1:-1] -
dt / dx * un[1:-1, 1:-1] *
(vn[1:-1, 1:-1] - vn[1:-1, 0:-2]) -
dt / dy * vn[1:-1, 1:-1] *
(vn[1:-1, 1:-1] - vn[0:-2, 1:-1]) +
nu * dt / dx**2 *
(vn[1:-1, 2:] - 2 * vn[1:-1, 1:-1] + vn[1:-1, 0:-2]) +
nu * dt / dy**2 *
(vn[2:, 1:-1] - 2 * vn[1:-1, 1:-1] + vn[0:-2, 1:-1])
)
v[1:-1, 1:-1] = (vn[1:-1, 1:-1] - dt / dx * un[1:-1, 1:-1] * (vn[1:-1, 1:-1] - vn[1:-1, 0:-2]) - dt / dy * vn[1:-1, 1:-1] * (vn[1:-1, 1:-1] - vn[0:-2, 1:-1]) + nu * dt / dx**2 * (vn[1:-1, 2:] - 2 * vn[1:-1, 1:-1] + vn[1:-1, 0:-2]) + nu * dt / dy**2 * (vn[2:, 1:-1] - 2 * vn[1:-1, 1:-1] + vn[0:-2, 1:-1]))
# vs
x_dot = dt / dx * un[1:-1, 1:-1]
y_dot = dt / dy * vn[1:-1, 1:-1]
v_diff_x = vn[1:-1, 1:-1] - vn[1:-1, 0:-2]
v_diff_y = vn[1:-1, 1:-1] - vn[0:-2, 1:-1]
v_diff_xy = vn[1:-1, 2:] - 2 * vn[1:-1, 1:-1] + vn[1:-1, 0:-2]
v_diff_yx = vn[2:, 1:-1] - 2 * vn[1:-1, 1:-1] + vn[0:-2, 1:-1]
v[1:-1, 1:-1] += (
- x_dot * v_diff_x - y_dot * v_diff_y
+ nu * dt / dx**2 * v_diff_xy
+ nu * dt / dy**2 * v_diff_yx
)
def foo(x): ...
"""Den här dokumentationen kan bara läsas av de som kan svenska!
"""
# vs
def foo(x): ...
"""This documentation can only be read by people who know swedish!
"""
Lets test some practical considerations
This is a tricky one... but there is an attempt
(Plot idea stolen from "Software Design by Example" by Greg Wilson)
Lets unpack the above a bit
Well defined interfaces are easy to grasp and use
The interface to the entire frames sub-package
def convert(t, states, in_frame, out_frame, **transform_kwargs):
...
from sorts import frames
...
states = frames.convert(t, states, "TEME", "ITRS")
Some more considerations
Let us re-visit during the design lecture!
Some recommendations
# Add a and b
c = a + b
def complex_doppler_drift_phasor(...):
"""Calculates the phase offsets (as complex numbers)
that a signal gets shifted by when the Doppler shift is
drifting linearly.
"""
Use a static website / document builder with a markup language
markup languages to use
Documentation building
Use a static website / document builder with a markup language
Accelerates understanding!
examples/ folderargparse or standard packageLast but not least:
who is your reader?
Further study and homework
Let's check out the handout above!