Tuesday, 31 May 2016

Formatting Go code

One of the best features of the Go tool portfolio is the "go fmt" command, in my opinion. This takes a file or a directory as parameter, and formats the Go code in a predetermined coding style. This has several advantages (see go fmt your code):

  • it becomes easier to write code - never again worry about how to format code, just run the formatter
  • it becomes easier to read code, since all Go code easily can be formatted to the same style
  • it becomes easier to maintain for the same reason
  • all discussions or bickering about code formatting issues goes away instantly

All of this makes for easier development and removes "coding noise". Best of all, the Go formatter can be integrated into lots of editors and IDEs. Then the formatting becomes transparent, so all that needs to be done is saving the code, and the formatter is run automatically.

No comments:

Post a Comment