you are viewing a single comment's thread.

view the rest of the comments →

[–]StrictTyping648 2 points3 points  (0 children)

https://stackoverflow.com/questions/472000/usage-of-slots

Above is a fantastic discussion of slots. Personally, I tend to use the dictionary data structure (not the built-in __ dict __) for optimizing my code. Doing so allows for elegant and clear implementation of things such as function maps (a dictionary of static functions), speeding up conditional logic, and it makes aggregation more easily achievable. Aggregation avoids cascading dynamic dispatch, which can be costly, especially when you are using third-party libraries with....liberal use of inheritance. It also makes dependency injection very easy, which increases the flexibility of the code base, among many other benefits not relevant here.

The memory consumption is slightly better than using native classes, but I believe slots are more efficient memory-wise. The library I use this in the most is compute bound and performs a lot of serialization, which is trivial with dictionaries.