Go fmt: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
Line 16: Line 16:
</syntaxhighlight>
</syntaxhighlight>


The tool formats source code files, by applying a predetermined layout, which includes a standard style of indentation and vertical alignment, and retains and if necessary reformats comments. One counterintuitive fact is that it uses the tab character for indentation. This is uncommon.
The tool formats source code files, by applying a predetermined layout, which includes a standard style of indentation and vertical alignment, and retains and if necessary reformats comments. For example, it lines up the fields of a structure and the associated comments. One counterintuitive fact is that it uses the tab character for indentation. This is uncommon.


Rob Pike: "[https://www.youtube.com/watch?v=PAAkCSZUG1c&t=523s gofmt style is no one's favorite, yet gofmt is everyone's favorite]".
Rob Pike: "[https://www.youtube.com/watch?v=PAAkCSZUG1c&t=523s gofmt style is no one's favorite, yet gofmt is everyone's favorite]".

Latest revision as of 23:25, 2 July 2024

External

Internal

Overview

gofmt is a program that operates at source file level.

go fmt operates at package level rather than source file level. go fmt delegates to gofmt, and it is equivalent to:

gofmt -l -w <file>

The tool formats source code files, by applying a predetermined layout, which includes a standard style of indentation and vertical alignment, and retains and if necessary reformats comments. For example, it lines up the fields of a structure and the associated comments. One counterintuitive fact is that it uses the tab character for indentation. This is uncommon.

Rob Pike: "gofmt style is no one's favorite, yet gofmt is everyone's favorite".