techhub.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A hub primarily for passionate technologists, but everyone is welcome

Administered by:

Server stats:

5.4K
active users

Jonathan Hall

How many problems or improvements can you spot in this real-world code example?

Hint: It works as intended, so it's not bugs, per se, I'm looking for.

@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.