-
Notifications
You must be signed in to change notification settings - Fork 3
Design Notes
Alex Ford edited this page Jul 31, 2018
·
2 revisions
Use an "object functional" style when possible.
To begin grokking see:
- "Boundaries", Gary Bernhardt: Program organization as a functional core and imperative shell, connected by simple object interfaces.
- "Enemy of the State", Justin Spahr-Summers: Representation of data types as "frozen"/"functional" objects.
- "Functional Core, Imperative Shell", @kbilsted: Collection of references the functional-object paradigm.
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 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
.
Mixin classes should be used, when possible, to abstract and isolate object behavior.