Go: Proposal: better name for *ast.File fields

Created on 5 Jul 2020  路  2Comments  路  Source: golang/go

What version of Go are you using (go version)?

go version go1.13.4 darwin/amd64

What did you do?

The Package and Name fields of *ast.File struct are a bit confusing.

It was an effort just to get the name of Package of a *ast.Field object because I thought *.ast.File.Name will be the name of the file. It was so obvious that I didn鈥檛 though of looking at the comments.
Thanks to Rui Santos for helping me out. Later I saw it was written in comments Name is Package name, not the file name.

What did you expect to see?

  • Instead of Name, something like PkgName would be better because it contains the package name of that file.
  • Instead of Package, maybe PkgPos can be more helpful name because it contains token Pos.

What did you see instead?

  • *ast.File.Name field containing the package name of the file is not intuitive.
  • *ast.File.Package field contains a Pos of package, so it's difficult to understand .

If it's there, I guess there must be some reason to name those fields like that, what I am unaware of.
But it was confusing for me.

Even if we decide to rename the fields, i think it won鈥檛 be that straight forward because it will start breaking the older versions.

Please share your thoughts.

/cc @rsc @griesemer

Proposal

Most helpful comment

They may be bad choices, but any change now would break the Go 1 compatibility guarantee (https://golang.org/doc/go1compat).

All 2 comments

They may be bad choices, but any change now would break the Go 1 compatibility guarantee (https://golang.org/doc/go1compat).

Based on 馃憤 from the OP closing as answered.

Was this page helpful?
0 / 5 - 0 ratings