eduvpn / eduvpn-common

Code to be shared between eduVPN clients
MIT License
5 stars 4 forks source link

Receiver arguments not consistent #4

Closed peske closed 1 year ago

peske commented 1 year ago

Receiver functions of the same type should have consistent receiver argument types. For example, if we have one function with receiver argument client *Client (note pointer type), like in:

https://github.com/eduvpn/eduvpn-common/blob/6229767a7d5b0d3cf3125f2e9da0ca0e66ada814/client/client.go#L22

then it should not have a function with receiver argument client Client (note value type), like in:

https://github.com/eduvpn/eduvpn-common/blob/6229767a7d5b0d3cf3125f2e9da0ca0e66ada814/client/client.go#L31

In my experience, for structure types it is almost always better to have pointer receivers than value receivers.

jwijenbergh commented 1 year ago

Good point

The main reason I use value types is that I keep reading that people recommend value receivers unless the struct becomes really big. However, as you might notice, most of the client functions also modify it which is why I used pointer receivers. I made the following rule:

But I agree that this is only confusing and I am not even consistent with these rules. Additionally, Go recommends to have one consistent receiver type per type. So I will stick to pointer receivers.

jwijenbergh commented 1 year ago

Should be mostly fixed now, thanks