ladybug-tools / honeybee

:honeybee: A python library to create, run and visualize radiance studies. Core library of Honeybee[+].
http://ladybug-tools.github.io/honeybee/docs
GNU General Public License v3.0
93 stars 25 forks source link

Duplicate RadianceParameters before assigning them to recipe #223

Open mostaphaRoudsari opened 6 years ago

mostaphaRoudsari commented 6 years ago

This is a [+] issue but we may want to make it a rule for all the recipes to avoid confusion. See this:

https://discourse.ladybug.tools/t/rad-parameter-hb/2947

mostaphaRoudsari commented 5 years ago

This turns out to be a deep issue with how descriptors work in relation to classes. Descriptors are assigned to classes and are shared between instances. As a result once the value is changed in one of the instances it will be updated in all the other instances.

There are workarounds to keep track of values in each instance but each have their own limitation. In most solutions the value is stored in instance itself and the descriptor calls it form the instance on get. The main use of descriptor in such case is to check the input values and not much more than that. Basically what properties which is an in-built descriptor does.

The solution above can be used to dynamically change the value in descriptor instance but that solution is not thread-safe.

Also this issue will only happen in case there are more than one instances of the class which uses the descriptor is in play otherwise everything will work as expected.

Related: https://stackoverflow.com/a/12645321/4394669

chriswmackey commented 5 years ago

@mostapha , These limitations were ultimately what drove me to build the ladybug core datatype module as it is instead of using descriptors. I would agree that, if you are considering using one of the workarounds to store values on the instance, you might as well just use the property decorator.