Hacker News new | ask | show | jobs
by andrewpolidori 903 days ago
The benefit of gofmt has nothing to do with "style" per se. Because it's standardized, tools can rely on its output. This means that you can easily write tools that handle go source code and interoperate well with each other
2 comments

Go's parser can be used on code with any formatting.
True, but there are times when doing some analyzes or refactoring that what one wants to operate on is go source directly, so the output of gofmt is easier and standardized and doesn't require handling the ast at all.
Can you give an example of such a tool that analyzes/refactors just the text output of gofmt?

It seems like that approach that would be fraught with errors considering how lenient gofmt can be at times but maybe it would be okay for simple stuff. e.g all of these ways of invoking methods:

   fmt.
           Println("Hello ",
                   "World",
           )

  fmt.Println("Hello ",
          "World")

  fmt.Println("Hello ", "World")
Do you have a source for this? It's always been my understanding that the creation of gofmt was almost entirely so that programmers would stop arguing about style.
Sorry I didn't mean to imply that wasn't a driving factor of it's creation. I should've said that it's a useful side effect