why support "gofmt" and "go fmt" two ways to format go code?

3,080 views
Skip to first unread message

jianfeng ye

unread,
Jan 13, 2015, 1:40:04 AM1/13/15
to golan...@googlegroups.com
I am confuse about gofmt and go fmt。

After when I install go 1.4, gofmt and go is install。If want to format a go file , I have two ways : go fmt a.go and gofmt a.go

what's the different between gofmt and go fmt, why need support two way to format go file?

And it seems offer recommand using gofmt install of "go fmt", because when i run "go help fmt":

[vagrant@localhost examples]$ go help fmt
usage: go fmt [-n] [-x] [packages]

Fmt runs the command 'gofmt -l -w' on the packages named
by the import paths.  It prints the names of the files that are modified.

For more about gofmt, see 'godoc gofmt'.
For more about specifying packages, see 'go help packages'.

The -n flag prints commands that would be executed.
The -x flag prints commands as they are executed.

To run gofmt with specific options, run gofmt itself.

See also: go fix, go vet.

If they are the same, why not delete one way.

Lucio

unread,
Jan 13, 2015, 1:59:47 AM1/13/15
to golan...@googlegroups.com
On Tuesday, 13 January 2015 08:40:04 UTC+2, jianfeng ye wrote:
I am confuse about gofmt and go fmt。

...
If they are the same, why not delete one way.

I think the answer is pretty obvious: go fmt does not provide all the capabilities of the underlying gofmt utility, so you use one for simple task and the other for special instances; users may find go fmt adequate and easy to use, while developers may need the extra features, for example.  They are certainly not equivalent. 

Lucio.

Jun Zhang

unread,
Jan 13, 2015, 2:06:19 AM1/13/15
to golan...@googlegroups.com
'go fmt', liking other go command, applies to a set of packages, which are a list of import paths. 

That is,  'go fmt [package ...]' may use $GOPATH to search package path and is a shorthand form of 'gofmt -l -w [/path/to/package ...]'

Benjamin Measures

unread,
Jan 13, 2015, 3:23:37 PM1/13/15
to golan...@googlegroups.com
On Tuesday, 13 January 2015 06:40:04 UTC, jianfeng ye wrote:
I am confuse about gofmt and go fmt。
[...]
If they are the same, why not delete one way.

They're not the same: one operates on [the underlying] files; the other on packages.

It's "Plumbing and Porcelain" (though the plumbing is quite nice to use too).

Rob Pike

unread,
Jan 13, 2015, 3:34:34 PM1/13/15
to Benjamin Measures, golan...@googlegroups.com
As far as I recall, porcelain is what you vomit into and plumbing is what carries the mess away.

You must be using some other definition of both. A quick google search did not enlighten me.

Meanwhile: The gofmt command will process the files given as arguments. The go fmt tool runs gofmt on all the files in the package paths given as arguments. Thus if I am in the encoding/gob directory,

   gofmt decode.go

will format the single file decode.go, while the tool run

  go fmt .

(. is actually the default) will format all the files in the encoding/gob package.

What makes that plumbing vs. porcelain remains mysterious.

For this still interested, the etymology of porcelain has its origins in the softness of a sow's nether regions. That "porc" in there is indeed a pig.

-rob



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamin Measures

unread,
Jan 13, 2015, 5:04:54 PM1/13/15
to golan...@googlegroups.com, saint....@gmail.com
On Tuesday, 13 January 2015 20:34:34 UTC, Rob 'Commander' Pike wrote:
As far as I recall, porcelain is what you vomit into and plumbing is what carries the mess away.

Porcelain is lovely to use but it's the plumbing that carries your "mess".

I suppose it's only plumbing and porcelain insofaras 'go fmt' uses gofmt under the covers and is in no way a reflection on the quality of the clay (which is pretty fine for each).

Reply all
Reply to author
Forward
0 new messages