srobo / j5

j5 - Framework for Robotics APIs
MIT License
9 stars 4 forks source link

Consider use of cached_property #350

Closed kierdavis closed 4 years ago

kierdavis commented 5 years ago

https://pypi.org/project/cached-property/

trickeydan commented 5 years ago

This is currently a dependency of zoloto, so I have no issue adding it here.

sedders123 commented 5 years ago

Where would this be useful? It may be useful in some places but right now I'm struggling to think of any methods that are computationally intensive enough to benefit from this. Could we come up with a list of expensive methods to help whoever picks this up?

kierdavis commented 5 years ago

Coordinate.cylindrical and Coordinate.spherical are already using explicit caching. Switching to cached_property would make the code a bit neater here.

It could also be used for Backend.firmware_version, though I think most backends retrieve the firmware version during initialisation in order to check it is a supported version.

trickeydan commented 5 years ago

Coordinate.cylindrical and Coordinate.spherical are already using explicit caching. Switching to cached_property would make the code a bit neater here.

I agree.

It could also be used for Backend.firmware_version, though I think most backends retrieve the firmware version during initialisation in order to check it is a supported version.

Thus the property is never fetched twice, the firmware version won't randomly change mid-execution.

kierdavis commented 5 years ago

It could also be used for Backend.firmware_version, though I think most backends retrieve the firmware version during initialisation in order to check it is a supported version.

Thus the property is never fetched twice, the firmware version won't randomly change mid-execution.

Sorry, I completely bodged what I was trying to say there I think. That's correct. What I was aiming to say was that we could move the retrieval of the firmware version into the firmware_version cached property itself, and then access it from the constructor if needed.

trickeydan commented 5 years ago

It could also be used for Backend.firmware_version, though I think most backends retrieve the firmware version during initialisation in order to check it is a supported version.

Thus the property is never fetched twice, the firmware version won't randomly change mid-execution.

Sorry, I completely bodged what I was trying to say there I think. That's correct. What I was aiming to say was that we could move the retrieval of the firmware version into the firmware_version cached property itself, and then access it from the constructor if needed.

I don't think we're disagreeing :P

trickeydan commented 4 years ago

Moved to 1.0.0.