Skip to content

Latest commit

 

History

History
106 lines (54 loc) · 2.63 KB

File metadata and controls

106 lines (54 loc) · 2.63 KB

Python for Humans (code organization)

Justin Lee

Website UIs

Lots of work to make them easy for humans to navigate and use

Structure and Scanning patterns

GUIs

People scan UI in predictable Z-shaped pattern

Code

People often scan directly to the bottom name=="main" because functions must be defined first, and that's where they're used.

Naming & Labeling

GUIs

Ambiguous naming conventions versus clearn names at potential cost of verbosity

Code

Short obscure or terse names (add, days, ok, fmt, check, etc., overloading function names) versus clear and potentially verbose but more informative names

Structure

Instead of one chunky block of code, provide spacing and group logically similar parts of the code. Use whitespace to separate distinct pieces of logic.

Visual hierarchy, progressive disclosure

GUI

FAQ example

Noisy and flat versus expanding hierarchy

Code

process_intake_notes example

timing data embedded in a function versus using a decorator to apply timing taking the timing code away from the main purpose and logic

Forms

GUI: Adoption application example

Lack of required field indicators. User should be focused on filling out the form rather than meta level figuring out how to fill out the form.

Placeholders for phone numbers, for example. Asterisk for required fields.

Code: submit_feedback function

Ambiguous variable names (a, b, c...)

Additive changes lead to fewer regressions, but adds a lot of technical debt and bloat. In adding arguments, people usually add paramters and defaults to a function rather than redesigning a function with new logic.

Takeaway: treat function as a form

GUI: Familiar structures

Form with fire icon buttons; button icon not intuitive. Improve with a trashcan icon to be more clear that the button is for deleting.

Code: filesystem structure

Nonidiomatic naming conventions versus predictable filenames corresponding to their purpose. Not prescriptive, may be particular to a development organization or even peronal projects.

Requires opening a file to confirm purpose.

Example: FastAPI codebase might be a good example for naming.

Standardization

GUI:

No explicit example

Code: linting/formatting tools

Code standardization

formatting and linting

black, ruff, flake8,

Type-checkers

pylance, mypy

Code Reviews, Ownership, Token Maxing

Code Reviews

Provide code quality feedback in a natural way

Ownership

Feel empowered for yourself or others to contribute to your code.

Token Maxing

Clean code, coupled with AI best practices can reduce token wastage.