4 ms·
You're intended to run gofmt on every save. golang is designed to be a sort of straight-jacket that forces everyone to write code in the same way (style etc) so
by aftbit 2y ago
You're intended to run gofmt on every save. golang is designed to be a sort of straight-jacket that forces everyone to write code in the same way (style etc) so that the junior devs can understand it clearly.
- grey-area 2y agoAnd so that people (of any level) don't bikeshed over silly things like tabs and spaces or { and newlines. I really like this about go - that it formats code for you, and miss it in other languages where we have linters but not formatters, which is a terrible idea IMO.
- School-Cotton 2y agoWhat mainstream languages don’t have formatters nowadays? Rust has rustfmt, C and related languages have clang-tidy, python has Black…
- grey-area 2y agoI mean built in that everyone uses. There are of course third party formatters.
- School-Cotton 2y agoYou can force everyone on a project to use a formatter just as easily in any of those languages as you can in Go, with a few lines in your CI job definitions. Whether they're third-party or not is irrelevant.
- Mawr 2y agoIt's not irrelevant, it's the entire point. The whole Go ecosystem uses a single formatter. There's no need to force anyone, everyone just uses gofmt. You will not be able to replicate that level of ubiquity easily at all.
- School-Cotton 2y agoNot really true because you have both gofmt and gofumpt, and gofmt can be run with -s or not, and also lots of projects are using separate linters to enforce maximum line length.
- mikeschinkel 2y agoBut true enough.
- guappa 2y agoNot true. Because after running go fmt and pushing our CI fails because of other stylistic concerns that are checked by another tool.
- mikeschinkel 2y agoYou can only force everyone on a project to use a formatter if you are the one who has the authority to decree what will be done on the team. OTOH, if you are but a team member and you join a team where the manager does not think common formatting is important, then you get f*ck all. So being built-in, idiomatic and expected cannot be over-appreciated.
- mistrial9 2y agothat's your preference but not universal
- grey-area 2y agoMy only preference is not to have to think about whitespace etc. I guess others who feel differently certainly wouldn't like Go, and that's ok!
- guappa 2y agoWhy are you talking about go fmt? I'm talking about parser of the go language If I write if x { bla } it will not compile, because the { needs to be on the same line as the X (for no reason whatsoever).