Go 1.13 adds the 0o form for octal numbers: instead of writing 0644 we can write 0o644. Gofmt is also changing to canonicalize 0O to 0o.
We should go one step further and have gofmt canonicalize the old style of octal literals to the 0o style: 0644 should be changed to 0o644.
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.
Go 1.13 adds the
0oform for octal numbers: instead of writing0644we can write0o644. Gofmt is also changing to canonicalize0Oto0o.We should go one step further and have gofmt canonicalize the old style of octal literals to the
0ostyle:0644should be changed to0o644.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.