I have a quick question - nothing important, just something I don’t understand and have wondered about:
in GHPython components, I understand that I should use this syntax to define a new DataTree object:
from Grasshopper import DataTree
from System import Object
my_new_DataTree_object = DataTree[Object]()
So, that all works fine of course. But I just wonder if someone can explain that python syntax for instantiating a new DataTree object? In particular, I’ve not seen the square bracket part used before when creating a new instance of a class, and just wondering what that’s doing in this case? Is this square bracket notation something particular to IronPython?
That's how you define types in ironpython (which is what grasshopper and Rhino are using). If I remember correctly you code both in C# and python. The C#'s <someType> syntax in ironpython is: [someType].
IronPython is Python implemented with C# instead of C. So you are writing C# code. Many data collections require to define a type. Usually a data collection which is bound to a certain type is more efficent. It doesn’t require casting/unboxing and the memory can be preallocated. Of course if you not preallocating and taking System.Object as type, then this doesn’t improve anything. But at least you can interface to other C# written code like Rhinocommon.
mylist = List[double](n) → a list for n-amount of doubles is better performing than saying mylist = List[Object]() or mylist = [] → a list of objects of undefined size.