3 ms·
Go ships with a tool called gofmt which automatically formats your code to a particular convention. It's expected that you gofmt all code that is released publi
by usea 14y ago
Go ships with a tool called gofmt which automatically formats your code to a particular convention. It's expected that you gofmt all code that is released publicly. It also solves more problems than it creates, even if I don't agree with all of its rules.
- chimeracoder 14y agoGo is much, much more strict than Python. Python is actually fairly forgiving when it comes to whitespace everywhere except for indentation. And for indentation, it doesn't complain as long as you're consistent (for both tabs vs. spaces, and if you choose spaces, consistent with the number of spaces). Go, on the other hand, checks for many aspects of style at compile-time. If you include an opening brace on the same line, import a package that isn't used, define a variable that isn't needed... all of those will cause compile-time errors. At first, it can get annoying - especially when you comment out a single line when debugging and then realize you have to make some other minor change elsewhere just to avoid one of the aforementioned style issues. But on the other hand, I can't deny that it makes my own code cleaner, and it probably saves some errors down the line. Furthermore, it made my code more consistent with existing Go code right from Day 1, even when I was just learning the language. Furthermore, for anybody who wants to do any metaprogramming/code translation, having a more rigid syntax enforced by the compiler is very helpful. Python doesn't do that. PEP8 is great, and I'm thankful that it's very widely followed. But it's much more powerful when these issues of "style" are made as mandatory as any other aspect of the language specification[1]. This "benevolent dictator" approach has its pluses and minuses, but having written Go code a short while now, I've come to appreciate some of its benefits in the case of coding style. [1] Okay, so the Go language specification doesn't include all of these, and yes, there are two independent Go compilers. But we can say that it's "mandatory" in the same way that we can say that "Python" has the GIL, when in reality many implementations don't (Jython, Iron Python, etc.)
- gte910h 14y agoI have little issue with complicated coding standards completely subsumed into the compiler. If you make me manually do paperwork every day, I will quit your thing