Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/gofmt: canonicalize octal literals to the '0o' form #33363
Go 1.13 adds the
We should go one step further and have gofmt canonicalize the old style of octal literals to the
Octal numbers are a surprising feature for programmers coming from a language that does not have them, or where they are rarely used. It's unintuitive that adding a leading zero to an integer changes its meaning. Some modern languages, such as Rust and Swift, have opted to omit the 0-prefix syntax altogether and only support the 0o form. Removing the 0-prefix syntax from Go would be too disruptive now, but we should strongly encourage use of the 0o form via this gofmt rule.
As a separate justification, with the new octal syntax there will be two different octal styles the programmer can choose. It's better for gofmt to remove this choice and enforce a single standard.
This will cause some churn in code bases, mostly around os.OpenFile and similar calls, but I believe the change is well worth it.
With Go 1.13, gofmt will already be canonicalizing integers to some extent:
Please no. This will result in lots of gratuitous churn, especially considering that many people will want to support older versions of Go for some time to come.
Maybe bring it up again once the new literal variants are understood by all gc versions still on support and the appropriate releases of gccgo (and other implementations of Go) have had a chance to propagate to their users.