With dataclasses, you get nice attribute access, error checking, a name for the aggregate data, and a more restrictive equality test. All good things.
Dicts are at the core of the language and are interoperable with many other tools: json, **kw, …
@yera_ee Dicts have a rich assortment of methods and operators.
People learn to use dicts on their first day.
Many existing tools accept or return dicts.
pprint() knows how to handle dicts.
Dicts are super fast.
Dicts underlie many other tools.
@yera_ee Embrace dataclasses but don't develop an aversion to dicts.
Python is a very dict centric language.
Mentally rejecting dicts would be like developing an allergy to the language itself. It leads to fighting the language rather than working in harmony with it.
#Python tip: Given inexact data, subtracting nearly equal
values increases relative error significantly more
than absolute error.
4.6 ± 0.2 Age of Earth (4.3%) 4.2 ± 0.1 Age of Oceans (2.4%)
___ 0.4 ± 0.3 Huge relative error (75%)
This is called “catastrophic cancellation”.
The subtractive cancellation issue commonly arises in floating point arithmetic. Even if the inputs are exact, intermediate values may not be exactly representable and will have an error bar. Subsequent operations can amplify the error.
1/7th is inexact but within ± ½ ulp.
A commonly given example arises when estimating derivatives with f′(x) ≈ Δf(x) / Δx.
Intuitively, the estimate improves as Δx approaches zero, but in practice, the large relative error from the deltas can overwhelm the result.