Hacker News new | past | comments | ask | show | jobs | submit login

Isn’t the point of go is that go fmt follows the languages global style guide?



Yeah, and that allows them to just write "all Go source files must conform to the format outputted by the gofmt tool" under "Formatting" and move on to the stuff for which a style guide is still needed...


It includes things that are not formatting specific like naming (https://google.github.io/styleguide/go/best-practices)


At first glance, that question makes sense; however, fmt doesn't cover all code format issues. Ex from the post:

> Line length

> There is no fixed line length for Go source code. If a line feels too long, it should be refactored instead of broken. If it is already as short as it is practical for it to be, the line should be allowed to remain long.

> Do not split a line:

> Before an indentation change (e.g., function declaration, conditional)

>To make a long string (e.g., a URL) fit into multiple shorter lines

fmt doesn't force arbitrarily short lines in lieu of readability (looking at you python + pep8; I can't recall how many lines of code were a few characters long and pep8 formatting made the multiple lines a mess to visually parse). The Google Team decided that it was important to not break up perfectly readable lines and gave guidance on how to do that.


I hate autoformatters/linters that frob with line length with a passion. I'm an 80-column kind of guy, but 81 columns can be just fine, and in some cases 90 or even 100 can be more readable than obsessively wrapping at 80 (or some other arbitrary value).

There are a few (rare) cases where gofmt will wrap lines, but it mostly leaves it alone which is one of the better "features" IMHO. Many *fmt tools really got this wrong.

Automated formatters are nice, but in the end there is no substitute for human eyes and common sense.


I hate this about default rustfmt.


Formatting ⊊ Style

Style may also include naming, documentation requirements, recommendations regarding function length, etc.


Go's fmt enforces some parts of formatting, like indentation, spaces vs. tabs and spacing around brackets and parentheses. But it is by no means a complete style guide. Fmt doesn't give your packages, structs or methods reasonable names automatically. Fmt doesn't tell you where to use values and where to use structs, what your interfaces should be, and how large your functions should be.

There is still room for a style guide.


Yes - I always thought that Go took an opinionated position that the style is whatever gofmt outputs. This is a very limited set of style "rules" - that is on purpose. gofmt is meant to allow one to spend near zero time manually styling code or picking people up on styling in reviews.


That is just a formatting guide. How to write spaces, newlines, semicolons.

Go fmt doesn't change anything that is not formatting.


Yet.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: