Today I learnt about @cached_property in python
As a classically trained physicist, my natural style of programming is functional.
But in production-level code, we usually want a mix of classes and functions.
However, this can get awkward.
THE CHICKEN AND EGG ATTRIBUTE DILEMMA
Oftentimes, we'll calculate some properties for a class and set them as attributes. Maybe it's the mean and standard deviation for our data class in machine learning, for example.
But that'd mean we have to initialise our class, load the data at initialisation and calculate those statistics.
That can be a bit silly in many cases.
Especially when we're building a larger class with some extra utility, this can quickly devolve into creating a monster at __init__.
Read more… [https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/] (2 min remaining to read)
#Functools #Python #TodayILearned #MachineLearning
Find more here: https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/