News for hackers. Stuff that matters.
Re:The Next Step for Generics by dgb23 on Tuesday June 16, 2020 @06:47PM (#23545255)
I cannot think of a language where errors cannot be ignored. In go it is easy to ignore them, but they stick out and can be marked by static analysis. The problems you describe are not solved at the language level, but by giving programmers enough time and incentives to write durable code.
Re:The Next Step for Generics by apta on Tuesday June 16, 2020 @08:55PM (#23546402)
The following line in golang ignores the error:

    fmt.Println("foo")
Compare to a language with exception handling where an exception will get thrown and bubbles up the stack until it either hits a handler, or crashes the program with a stack trace.

And I was referring to accidental ignoring. I've seen variations of the following several times now:

    res, err := foo("foo")
    if err != nil { ... }
    if res != nil { ... }
    res, err = foo("bar")
    if res != nil { ... }
Re:The Next Step for Generics by Mawr on Tuesday June 16, 2020 @11:07PM (#23547298)
Usage of linters fixes this:

>The following line in golang ignores the error:

   fmt.Println("foo")
fmt.Println() is blacklisted for obvious reasons, but this:

    a := func() error {
        return nil 
    }
    a()
results in:

    go-lint: Error return value of 'a' is not checked (errcheck)
>And I was referring to accidental ignoring. I've seen variations of the following several times now:

    res, err := foo("foo")
    if err != nil { ... }
    if res != nil { ... }
    res, err = foo("bar")
    if res != nil { ... }
results in:

    go-lint: ineffectual assignment to 'err' (ineffassign)
Re:The Next Step for Generics by apta on Tuesday June 16, 2020 @11:50PM (#23547550)
> fmt.Println() is blacklisted for obvious reasons

That's the issue with the language, there are so many special cases for convenience sake, not for correctness sake. It's obvious why it's excluded, but it doesn't make it correct. Do you want critical software written in such a language?

Furthermore, does that linter work with something like gorm (https://gorm.io/) and its way of handling errors? It's extremely easy to mis-handle errors with it. It's even a widely used library.

Re:The Next Step for Generics by geodel on Tuesday June 16, 2020 @11:02PM (#23547261)
Huh, I have seen enough catch blocks in Java code at work which are totally empty. How is that better than ignoring error?
Re:The Next Step for Generics by apta on Tuesday June 16, 2020 @11:51PM (#23547558)
Because it's an explicit opt-in, as opposed to accidental opt out. And static checking can warn you about empty catch blocks.
Re:The Next Step for Generics by umanwizard on Tuesday June 16, 2020 @11:11PM (#23547318)
In rust, errors are difficult to ignore (you need to either allow compiler warnings, which AFAICT nobody sane does, or write something like `let _ = my_fallible_function();` which makes the intent to ignore the error explicit).

Perhaps more fundamental: it’s impossible to accidentally use an uninitialized “success” return value when the function actually failed, which is easy to do in C, C++, Go, etc.

Re:The Next Step for Generics by ori_b on Wednesday June 17, 2020 @12:03AM (#23547639)
Or .unwrap(), which I see relatively often.
Re:The Next Step for Generics by umanwizard on Wednesday June 17, 2020 @08:43AM (#23550684)
That’s not ignoring errors, it’s explicitly choosing what to do in case of one (crash).