diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-06-16 11:27:48 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-06-17 09:42:50 +0300 |
commit | 831809da197db9dde6b85efaa66c41f60312d8d1 (patch) | |
tree | d586da4f00ca955899d411c1ed0dc039d895b4c4 /STYLE.md | |
parent | 938bce6574120db9009215f63681a89d0eef7407 (diff) |
STYLE: Clarify when to use pointer or value receivers
Our current policy with regards to pointer vs. value receivers is not
documented anywhere. Given that we have a policy saying that if a single
method requires a pointer receiver, all methods should be pointer
receivers, there's some non-obvious bits to our coding style. So let's
write this part down so we can point to it from now on.
Diffstat (limited to 'STYLE.md')
-rw-r--r-- | STYLE.md | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -144,7 +144,14 @@ digits, but then you may not use a `4` as the first digit. 0377 equals hexadecimal you cannot make this mistake because the largest two digit hex number is 0xff which equals 255. -## Return statements +## Functions + +### Method Receivers + +Without any good reason, methods should always use value receivers, where good +reasons include (but are not limited to) performance/memory concerns or +modification of state in the receiver. Otherwise, if any of the type's methods +requires a pointer receiver, all methods should be pointer receivers. ### Don't use "naked return" |