How many problems or improvements can you spot in this real-world #Go code example?
Hint: It works as intended, so it's not bugs, per se, I'm looking for.
Here's my write-up on what I would do to improve this code:
https://boldlygo.tech/archive/2025-03-31-whats-wrong-with-this-code-answered/
@jhall
- why trim the equal sign, if it is necessary for some standard b64?
- put the decoder functions in a loop
- depending on the application, it might be worth considering to skip the guesswork and instead require valid b64 of some flavour
@mpldr Great observations! The first point is the most important--why trim padding, if it makes the first two decoding methods invalid?
My final solution was to just remove the first two encodings and jump straight to the only one that could possibly work ;)
@jhall I saw the answer. But regardless of the logic, the way you used the nested `if` is just driving me crazy
Why simply not go for:
```go
result, err := func1()
If err == nil {
return result, nil
}
result, err = func2()
if err == nil {
return result, nil
}
```
@0xZogG You'd have to ask the person who wrote the code.