altavir12/14/2021, 4:14 PM
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?
zaleslaw12/14/2021, 5:49 PM
altavir12/14/2021, 5:50 PM
zaleslaw12/14/2021, 5:55 PM
altavir12/14/2021, 5:58 PM
Alexandre Brown12/17/2021, 2:59 AM
, 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
I wouldn't expect any computation. But when I do
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).
zaleslaw12/17/2021, 8:13 AM
Alexandre Brown12/17/2021, 12:01 PM