Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Go and Versioning: Minimal Version Selection. Parent comment
Let's say I have this program (which was goformatted):
package main import ( "fmt" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) }
package main import ( "fmt" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) log.Print("test") }
package main import ( "fmt" "log" ) // commenting... // commenting... func main() { fmt.Println("hello", "world") fmt.Println( "hello", "world", ) log.Print("test") }
There are no comments on this comment yet.
Let's say I have this program (which was goformatted):
And I had log.Print("test") at the end of main(): Then I run goimports to automatically update the import directive (goimports parses the source to build an AST, then modifies the AST, then reconverts it to source code): Everything is kept exactly as-is, except the added line "log" in the import directive. This round-trip mechanism is the main benefit of gofmt.