Skip to content

Commit

Permalink
docs: Added minor note to single rule. (#2422)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka authored Apr 13, 2020
1 parent 52c7eaf commit 0bb3b3b
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions docs/contributing/coding-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,6 @@ type: docs
menu: contributing
---

<style>
table {
border: 1px solid;
max-width: 100%;
overflow: auto;
word-wrap: break-word;
}

th {
text-align: center;
}

th, td {
max-width: 100%;
overflow: auto;
word-wrap: break-word;
}
</style>

# Thanos Coding Style Guide

This document details the official style guides for the various languages we use in the Thanos project.
Expand Down Expand Up @@ -373,9 +354,9 @@ NOTE: Why you cannot just allocate slice and release and in new iteration alloca
available space and just reuses that no? (: Well, it's not that easy. TL;DR is that Go Garbage Collection runs periodically or on certain cases
(big heap), but definitely not on every iteration of your loop (that would be super slow). Read more in details [here](https://about.sourcegraph.com/go/gophercon-2018-allocator-wrestling).

<table style="width: 100%; max-width: 100%;">
<table>
<tbody>
<thead align="center"><tr><th>Avoid 🔥</th></tr></thead>
<tr><th>Avoid 🔥</th></tr>
<tr><td>

```go
Expand Down Expand Up @@ -758,6 +739,19 @@ func function(
</td></tr>
</tbody></table>
This applies for both calling and defining method / function.
NOTE: One exception would be when you expect the variadic (e.g. `...string`) arguments to be filled in pairs, e.g:
```go
level.Info(logger).Log(
"msg", "found something epic during compaction; this looks amazing",
"compNumber", compNumber,
"block", id,
"elapsed", timeElapsed,
)
```
#### Control Structure: Prefer early returns and avoid `else`
In most of the cases, you don't need `else`. You can usually use `continue`, `break` or `return` to end an `if` block.
Expand Down

0 comments on commit 0bb3b3b

Please sign in to comment.