News for hackers. Stuff that matters.
Re:Everyday hassles in Go by frou_dh on Tuesday December 30, 2014 @08:03AM (#8814390)
> ... error verifications in Go ... you understand by reading your code the places where error can occur or where you decided to ignore errors (By using _)

This compiles:

    package main

    import "errors"

    func main() {
        f()
        println("hello erroneous world")
    }

    func f() error { return errors.New("boo") }
Re:Everyday hassles in Go by NateDad on Tuesday December 30, 2014 @08:15AM (#8814434)
Which you can catch with a linter like https://github.com/kisielk/errcheck. Errors in Go are just values. There's nothing "more wrong" about ignoring a return value that is an error or one that is file handle, for example. And in cases where a function returns an error and a value (where the error generally indicates the validity of the value), you'll get a compile error if you don't check the error. That's pretty good for basically zero overhead.
Re:Everyday hassles in Go by frou_dh on Tuesday December 30, 2014 @08:29AM (#8814476)
> And in cases where a function returns an error and a value (where the error generally indicates the validity of the value), you'll get a compile error if you don't check the error.

This compiles:

    package main
    import "errors"
    func main() {
        x, err := f()
        if err != nil {
            return
        }
        y, err := g()
        h(x, y)
    }
    func f() (x int, err error) { return 1000, nil }
    func g() (y int, err error) { err = errors.New("boo"); return }
    func h(x, y int) { println(x/y) }
(I do write Go most days and rather like it, but apologists for its weak parts are legion)
Re:Everyday hassles in Go by NateDad on Tuesday December 30, 2014 @09:47AM (#8814756)
Pretty sure errcheck will catch that too. The thing that bugs me is the people that make up problems that are not at all problems in real day to day coding.
Re:Everyday hassles in Go by ominous_prime on Tuesday December 30, 2014 @09:54AM (#8814792)
This looks more like a bug. The second err is a valid redeclaration, and so should be checked for usage on it's own. Though the redeclaration through multiple assignment is itself a bit of a wart that the programmer hast to be wary of, so it may not be a big deal.

In any case, the go compiler is very helpful in most cases, and better tooling can improve things further.

Re:Everyday hassles in Go by NateDad on Wednesday December 31, 2014 @09:37AM (#8819467)
FYI the second use is just assignment, that's why it's not caught by the unused variable rule.
Re:Everyday hassles in Go by ominous_prime on Wednesday December 31, 2014 @10:11PM (#8822020)
Ah right. It only shadows if it's a new scope.
Re:Everyday hassles in Go by cjslep on Tuesday December 30, 2014 @08:08AM (#8814403)
Sure, you can fail to capture any return variable (not just errors) in lots of languages. What is available to Go that isn't in, say, C++ or Java is the "black-hole variable" marked with the underscore _ so its very much a stylistic choice to insert it in Go where errors would be returned. Applied consistently, you can gain a lot of readability. But it is very much a stylistic choice.