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...
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:
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
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.