prometheus/tsdb/chunkenc
beorn7 5b53aa1108 style: Replace else if cascades with switch
Wiser coders than myself have come to the conclusion that a `switch`
statement is almost always superior to a statement that includes any
`else if`.

The exceptions that I have found in our codebase are just these two:

* The `if else` is followed by an additional statement before the next
  condition (separated by a `;`).
* The whole thing is within a `for` loop and `break` statements are
  used. In this case, using `switch` would require tagging the `for`
  loop, which probably tips the balance.

Why are `switch` statements more readable?

For one, fewer curly braces. But more importantly, the conditions all
have the same alignment, so the whole thing follows the natural flow
of going down a list of conditions. With `else if`, in contrast, all
conditions but the first are "hidden" behind `} else if `, harder to
spot and (for no good reason) presented differently from the first
condition.

I'm sure the aforemention wise coders can list even more reasons.

In any case, I like it so much that I have found myself recommending
it in code reviews. I would like to make it a habit in our code base,
without making it a hard requirement that we would test on the CI. But
for that, there has to be a role model, so this commit eliminates all
`if else` occurrences, unless it is autogenerated code or fits one of
the exceptions above.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-04-19 17:22:31 +02:00
..
bstream.go tsdb: stop saving a copy of last 4 samples in memSeries (#11296) 2022-09-27 19:32:05 +05:30
bstream_test.go Testify: move to require (#8122) 2020-10-29 09:43:23 +00:00
chunk.go Add support for native histograms to concreteSeriesIterator 2023-04-06 09:54:15 -07:00
chunk_test.go tsdb: Rework iterators (#9877) 2021-11-29 13:24:23 +05:30
float_histogram.go lint: Adjust to the lint warnings raised by current versions of golint-ci 2023-04-19 17:10:10 +02:00
float_histogram_test.go lint: Adjust to the lint warnings raised by current versions of golint-ci 2023-04-19 17:10:10 +02:00
histogram.go lint: Adjust to the lint warnings raised by current versions of golint-ci 2023-04-19 17:10:10 +02:00
histogram_meta.go histograms: Return actually useful counter reset hints 2023-01-25 16:57:21 +01:00
histogram_meta_test.go histograms: General readability tweaks 2023-01-19 13:26:42 +01:00
histogram_test.go lint: Adjust to the lint warnings raised by current versions of golint-ci 2023-04-19 17:10:10 +02:00
varbit.go tsdb: Update comment about a possible space optimization (#11303) 2022-09-15 13:11:57 +05:30
varbit_test.go Use more varbit in histogram chunks 2021-10-13 20:03:35 +02:00
xor.go style: Replace else if cascades with switch 2023-04-19 17:22:31 +02:00
xor_test.go chunkenc: Slightly optimize xorWrite/xoRead (#11476) 2022-10-20 15:08:01 +05:30