3 ms·
Copy Slices and Maps at Boundaries: https://github.com/uber-go/guide/blob/master/style.md#copy-slices-and-maps-at-boundaries https://github.com/uber-go/guide/bl
by tapirl 7y ago
Copy Slices and Maps at Boundaries: https://github.com/uber-go/guide/blob/master/style.md#copy-slices-and-maps-at-boundaries https://github.com/uber-go/guide/blob/master/style.md#copy-s...
The suggested good clone is not very efficient: https://github.com/go101/go101/wiki/How-to-efficiently-clone-a-slice%3F https://github.com/go101/go101/wiki/How-to-efficiently-clone...
In fact, I prefer the suggested bad one instead. We should let the caller to determine whether or not a clone is needed.
--------------------------
Start Enums at One: https://github.com/uber-go/guide/blob/master/style.md#start-enums-at-one https://github.com/uber-go/guide/blob/master/style.md#start-... Any reason here? (Edit: I just missed the reason. However, I think there should be a default value for most enums and most of the default values should zero.)
--------------------------
Local Variable Declarations: https://github.com/uber-go/guide/blob/master/style.md#local-variable-declarations https://github.com/uber-go/guide/blob/master/style.md#local-...
Personally, I prefer "var x = ..." and think short variables should be used as limited as possible. I remember that Go team has a not-very-concrete plan to depreciate short variable declarations.
--------------------------
Avoid Naked Parameters: https://github.com/uber-go/guide/blob/master/style.md#avoid-naked-parameters https://github.com/uber-go/guide/blob/master/style.md#avoid-...
This suggestion has its own drawback. When a parameter name changed, all the places using it must be modified to keep consistent. This is one reason why Go team rejected named arguments.
If this must be done, I recommend to define and use some named bool constants instead.
- sanxiyn 7y agoRe: Start Enums at One. As explained, it is to avoid making the first enum value the default when making it the default is not appropriate.
- gen220 7y agoAt my place of work, we pretty much always make the default (0) value “Unspecified”. The rationale is, it’s often quite useful to know that the originator hasn’t specified a value, and to help new originators avoid unintended side-effects. This style guide has the same effect, but it’s implicit; takes a few more mental cycles to parse in exchange for less code. Personally, I think it’s probably worth the trade off to type it out once and save time thinking later.