DEV Community

Discussion on: What simple things annoy you about your favourite programming languages?

Collapse
 
adnanademovic profile image
Adnan Ademovic • Edited

Golang is one of my favorites, but writing the same thing over and over annoys me more than anything. I'm talking, of course, about:

result, err := somethingThatCanFail(args)
if err != nil {
    return nil, err
}
Enter fullscreen mode Exit fullscreen mode

Edit: I'm also aware that you can use named return types to do the simplified version below.

if err != nil {
    return
}
Enter fullscreen mode Exit fullscreen mode

There should be a syntax shorthand for commonly used stuff like this. Rust has the try!() macro that does this, or even shorter, the ? operator.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

This is one of my core complaints about Go. I'm quite opposed to explicit error handling since ultimately coders will just forget it in places, or not check it correctly. I'm in favour of errors propagating by default, and having a nice option to catch them if you want.

Any repetition is syntax is bad for readability. The intent of the code gets lost in overhead.