altavir
12/14/2021, 4:14 PMmodelhub[...]
Is it a good idea to use get operation for something that could be slow or accesses the disk? Or the cache is loaded in the constructor?zaleslaw
12/14/2021, 5:49 PMaltavir
12/14/2021, 5:50 PMzaleslaw
12/14/2021, 5:55 PMaltavir
12/14/2021, 5:58 PMAlexandre Brown
12/17/2021, 2:59 AMmyClass.myState
, if it can be non existent then having it nullable would be expected).
If we are talking about fetching something which might be cached or might not and might need a network call then I wouldn't expect that from a property since property don't support suspending.
If it is a function then it is fine in my opinion since a function could be suspendable.
For instance when we have myClass.result
I wouldn't expect any computation. But when I do myClass.getResult()
then I'm expecting a computation of some sort. If it uses the cached value, then it's fine but I'd consider that an implementation detail for the function.
This is mainly backed by the fact that we tend to use property in kotlin instead of getter functions therefore when I see a get function I generally assume it represents an operation Instead of a state.
This is coherent with the fact that a StateFlow has a property for the current state (which simply returns the value, no computation).zaleslaw
12/17/2021, 8:13 AMAlexandre Brown
12/17/2021, 12:01 PM