Skip to content

Design Notes

Alex Ford edited this page Jul 31, 2018 · 2 revisions

"Object Functional Style"

Use an "object functional" style when possible.

To begin grokking see:

  1. "Boundaries", Gary Bernhardt: Program organization as a functional core and imperative shell, connected by simple object interfaces.
  2. "Enemy of the State", Justin Spahr-Summers: Representation of data types as "frozen"/"functional" objects.
  3. "Functional Core, Imperative Shell", @kbilsted: Collection of references the functional-object paradigm.

Data Classes

Use of attrs-based data classes as primary data types.

Data classes should be preferred over dicts, tuples and other forms of class definition whenever possible.

Data classes should be cohesive and be oriented around a single responsibility. ...but an objects responsibility may be to contain two independent objects.

Factory Functions

Factory functions should be preferred over the use of complex constructors, abstracting class initialization from the attrs-based __init__.

Factory functions from primitive (ie. dicts, tensors, ...) or lower-level types should be defined as a dataclass @classmethod.

Mixins

Mixin classes should be used, when possible, to abstract and isolate object behavior.

Clone this wiki locally