News for hackers. Stuff that matters.
Re:On Go by AlisdairO on Sunday June 02, 2013 @06:30AM (#5807976)
> I'm not clear on which error check you think you might "forget". If you're performing an operation that can fail, wouldn't that be a clue that you need to check for failure?

Sure - and the possibility of exceeding the bounds of an array would be a clue that you need to bounds check, but there's still a hell of a lot of C code out there with array overflow errors. You can argue that people who make these errors are bad programmers, but that's fairly irrelevant - most programmers of any level will end up working with code with errors in it at some point. Exception stack traces are an extremely useful way to find out where something went wrong when someone failed to do some necessary error checking.

I have no experience with Go, so I'm not saying what it does is wrong - I'm just curious. Say a customer experiences a failure with your software caused by some missing/incorrect error handling, what do you do to work out what happened?

Re:On Go by nknighthb on Sunday June 02, 2013 @06:58AM (#5808030)
> the possibility of exceeding the bounds of an array

Not possible in Go, the runtime will panic.

> there's still a hell of a lot of C code out there with array overflow errors

An extremely easy error to make in many cases, which is why modern programming languages bounds-check.

> Exception stack traces

Go will give you a very nice stacktrace should it ever panic.

> I have no experience with Go

Which is really the problem. People keep arguing about Go's merits based on no substantive understanding.

It's very obvious which operations can fail without a panic in Go, because functions explicitly return error objects -- actual error objects, not magic numbers. The return signature for the Go equivalent of fread is (int, error), not (int).

Re:On Go by micampe on Sunday June 02, 2013 @10:32AM (#5808640)
> Which is really the problem. People keep arguing about Go's merits based on no substantive understanding.

They are not arguing, they are asking questions to improve their understanding.

Re:On Go by nknighthb on Sunday June 02, 2013 @11:50AM (#5808932)
That may have been too harsh in reply to AlisdairO specifically, in which case I apologize.

The context of the thread, however, very much is people arguing. See for example graue's post a few levels up.

Re:On Go by graue on Sunday June 02, 2013 @02:31PM (#5809562)
While I may have phrased my post somewhat harshly, I too asked because I wished to improve my understanding, and the responses have definitely helped.
Re:On Go by pjmlp on Sunday June 02, 2013 @07:29AM (#5808111)
> > the possibility of exceeding the bounds of an array > Not possible in Go, the runtime will panic.

Is -B for disabling bounds checking no longer supported?

Re:On Go by nknighthb on Sunday June 02, 2013 @07:47AM (#5808152)
I see no such option documented, and I would certainly never enable such a thing in real code.
Re:On Go by pjmlp on Sunday June 02, 2013 @08:58AM (#5808317)
It was never documented, but any long time Go user knows about it.

Looking at the code it seems it has been removed.

> ... I would certainly never enable such a thing in real code.

So I assume you don't do C or C++. :)

While I agree with you, there are certain cases where it might help. That is why most strong typed languages with native compilers allow to selectively disable bounds checking, since the Pascal/Modula-2 days.

I only support doing this if profiling proves it is really worth it, give the security issues.

Re:On Go by burntsushi on Sunday June 02, 2013 @12:49PM (#5809159)
I think it's still there.

    package main

    func main() {
        slice := []string{"first", "second", "third"}
        println(slice[1])
        slice = slice[0:2]
        println(slice[2])
    }
Compile with

    go build -gcflags -B wat.go
    ./wat
Output

    second
    third
Without the `-B` you'll get a runtime panic. I'm on Go 1.1. (Maybe it's removed in tip?)
Re:On Go by pjmlp on Sunday June 02, 2013 @02:09PM (#5809473)
Ah ok, I was trying to locate it via the browser.

Next time I better checkout and do a proper grep.

Re:On Go by nknighthb on Sunday June 02, 2013 @09:32AM (#5808429)
> So I assume you don't do C or C++. :)

If C had a simple universal switch for bounds checking, I'd turn it on everywhere and immediately revoke commit privileges for anyone on my team who turned it back off. But it doesn't, and necessarily can't, making your statement nothing more than an annoying exercise in wrongful pedantry. It is contextually obvious I was talking about Go code and/or languages/compilers with such a switch.

Re:On Go by pjmlp on Sunday June 02, 2013 @02:12PM (#5809491)
I was trying you out, because if you make such a statement then I am lead to believe you stay away from languages that don't provide control over bounds checking.
Re:On Go by burntsushi on Sunday June 02, 2013 @12:45PM (#5809142)
See the output of

    go tool 6g -help
The `-B` switch will disable bounds checks. You can use it like this:

    go build -gcflags '-B'