News for hackers. Stuff that matters.
Re:Introduction to Go 1.1 by ubershmekel on Tuesday March 26, 2013 @04:40AM (#5441918)
> In Go 1.1, an integer division by constant zero is not a legal program, so it is a compile-time error

How often do be people accidentally divide by a constant 0? I personally use that to simulate runtime errors all the time in python. It's shorter than writing "raise Exception()".

Re:Introduction to Go 1.1 by jsmeaton on Tuesday March 26, 2013 @07:25AM (#5442460)
I'm not familiar with Go, but I'd imagine something like this:

  const int SomeNumber = 0;
  // then much later in the program
  return 3 / SomeNumber;
An accidental and not immediately obvious divide by constant 0.
Re:Introduction to Go 1.1 by JulianMorrison on Tuesday March 26, 2013 @07:48AM (#5442546)

  const weasels = 5    
  const lawyers = 5    
  const mustelids = weasels - lawyers

  feedWeaselsEach(chickenPortions / mustelids)
Re:Introduction to Go 1.1 by netcraft on Tuesday March 26, 2013 @10:45AM (#5443600)
would this count as a constant 0 and be caught by the compiler?
Re:Introduction to Go 1.1 by JulianMorrison on Tuesday March 26, 2013 @10:48AM (#5443627)
Yup. Constants are computed at compile time in Go.
Re:Introduction to Go 1.1 by laumars on Tuesday March 26, 2013 @06:31AM (#5442246)

    > How often do be people accidentally divide by a constant 0?
As much as I do love the level of checking that Go's compiler does, I must admit I asked myself that same question when I read the article.
Re:Introduction to Go 1.1 by dsymonds on Tuesday March 26, 2013 @06:34AM (#5442258)
Go has a builtin function called panic, which is much more useful and well-defined. panic("simulated runtime error")
Re:Introduction to Go 1.1 by IanCal on Tuesday March 26, 2013 @07:22AM (#5442455)
> How often do be people accidentally divide by a constant 0?

Depends how far the compiler goes to simplify constant expressions. It could be quite useful if it detects something like:

f(x,y) : x / (x - (2*y))

f(6,3)

Re:Introduction to Go 1.1 by enneff on Tuesday March 26, 2013 @11:58AM (#5444130)
This change was added to ratify an assumption that the compiler had already made. As has been pointed out, this is not a big deal. Almost nobody is affected, but our release notes must be comprehensive.
Re:Introduction to Go 1.1 by duaneb on Tuesday March 26, 2013 @05:30AM (#5442075)
It's possibly easier to specifically handle that corner case.
Re:Introduction to Go 1.1 by verytrivial on Tuesday March 26, 2013 @07:02AM (#5442367)
What about programs that write programs that divide by zero?
Re:Introduction to Go 1.1 by yebyen on Tuesday March 26, 2013 @02:43PM (#5445235)
If those programs (the second level of programs) are compiled with the go compiler too, then they will also be caught (and sacked.)