News for hackers. Stuff that matters.
Re:In praise of Go or "Why I moved from Python and C++ to Go" by kjksf on Wednesday November 17, 2010 @12:45AM (#1913070)
I wrote a lot of code of C/C++ and my implicit assumption is that C syntax is serviceable. Since I don't see C syntax (or JavaScript syntax or Java syntax) as a major problem and Go is an improvement over those, I don't see Go syntax as a major problem.

I agree with you that Python's syntax is cleaner but I would like to bring few novel syntax-related things that Go did that are not as commonly known and in some cases are improvements even over Python.

In general I don't like deep indentation and Go has few things to help keep indentation to a minimum.

1. defer statement

In Go you can say:

  f := os.Open("myfile.dat", ...)
  defer f.Close()
That guarantees that f.Close() will be called at function exit. In Python/Java/C# to get the same guarantee, you would have to use try/finally block, introducing additional indentation for the code using f.

2. Syntax for defining methods on interfaces

  func (p *MyClass) Method(int i) {
    return p.x + i
  }
The equivalent in Python would be:

class MyClass(): def Method(i): return this.x + i

Again, less indentation.

3. panic()/recover() way of handling fatal errors also doesn't introduce additional indentation level like try/catch blocks.

Re:In praise of Go or "Why I moved from Python and C++ to Go" by andralex on Wednesday November 17, 2010 @01:02AM (#1913107)
If you like defer's or panic's savings on indentation, you're in desperate need of D: http://www.digitalmars.com/d/2.0/statement.html#ScopeGuardSt...