Reduce usage of untyped interface{} and casting
olabiniV2 opened this issue · comments
We have a large amount of places - especially in interactions with other parts of Coy - where the GUI uses the interface{}
type and then casts it in different ways. Sometimes, we also use more specific types, but then do type-switches anyway. We should try to rely more on the compiler to help us give advice when we're doing things that are problematic by reducing use of type switches.
There are two big areas where we should be extra careful with this. The first one is with all the MUC message code. Here, we wanted to separate the implementation of the data-types from the session/muc/data
package from the representation of messages and other actions. For this reason, type-switches are used a lot - and in some cases just regular switches but based on pseudo-types, such as IsOwner
, etc. We should move to using the Visitor
pattern for most of these places.
The other place is where we are interacting with different parts of GTK that is untyped. For example, in the ListModel
storage, and also using GLib properties. In this places, we should implement wrapping structures or methods, and reduce the place that calls the untyped functionality as much as possible.