News for hackers. Stuff that matters.
Re:Go and Versioning: Minimal Version Selection by ngrilly on Friday February 23, 2018 @07:04AM (#16445802)
I don't get your point.

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",
        )
    }
And I had log.Print("test") at the end of main():

    package main

    import (
        "fmt"
    )

    // commenting...
    // commenting...

    func main() {
        fmt.Println("hello", "world")
        fmt.Println(
            "hello",
            "world",
        )
        log.Print("test")
    }
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):

    package main

    import (
        "fmt"
        "log"
    )

    // commenting...
    // commenting...

    func main() {
        fmt.Println("hello", "world")
        fmt.Println(
            "hello",
            "world",
        )
        log.Print("test")
    }
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.

There are no comments on this comment yet.