Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Unified codestyle

The moment I got my first compile error due to an unused variable and an unused import, made me realize Go is not a serious programming language.



The moment you see that you had misspelled a variable name by a single character when the compiler warned you about an unused variable, you'll realize Go is a serious programming language.


This has saved me minutes of confusion so many times.


I wonder who hurt them, that is, how much did unused variables/imports hurt at Google for them to make those a compiler error?

Insofar I know it, I can imagine C/C++ caused some issues like that because it's hard to figure out whether an import is used, but an unused import does have a cost.


https://research.swtch.com/deps#watch_your_dependencies

> Creeping dependencies can also affect the size of your project. During the development of Google’s Sawzall—a JIT’ed logs processing language—the authors discovered at various times that the main interpreter binary contained not just Sawzall’s JIT but also (unused) PostScript, Python, and JavaScript interpreters. Each time, the culprit turned out to be unused dependencies declared by some library Sawzall did depend on, combined with the fact that Google’s build system eliminated any manual effort needed to start using a new dependency.. This kind of error is the reason that the Go language makes importing an unused package a compile-time error.


I think the fundamental reason behind this behavior is just Go's rejection of the concept of compiler warnings. Unused variables must either be A-ok or trigger an error. They chose the second option for unused variables. Some other code smells are considered A-ok by the compiler and need to be caught by linters.


The problem with such rejection is that every serious project written in Go has invented compiler warnings outside the compiler, with linters.


Why is it a problem?

`go vet` is part of Go toolchain so the designers very much understand and acknowledge that code can have issues that are not always errors.

The distinction they made is very simple: an error is something that is always wrong and a vet warnings is something that is possibly wrong but not always.

They made a judgement call to split the responsibility: compiler only reports errors, other tools, including `go vet`, can tell you about other issues.

For example: passing a large struct by value to a function is potentially a performance problem but it's also correct code.

If you ever tried to compile C++ code with different compilers you would know why it's a wise decision.

The set of warnings is vast and not standardized so you take C++ source from project. It compiles for them but doesn't compile for you because you use different compiler or enabled different set of warnings. At which point you either try to get the other project to "fix" something that isn't an issue for them or you do stupid, pointless, time consuming work adjusting your build system.

The same would happen in Go and it would be a reusability killer. You use some library in your program but it doesn't compile because you decided to use more strict set of flags.

Lack of warnings switches also simplifies the toolchain. In go it's just `go build` and it works.

In C++ you have to write some kind of makefile because everyone executes `cc` with different set of flags.


Is this a problem? Linters are also used with lots of languages that do have compiler warnings. Go just removes the no man’s land between honest-to-goodness compiler errors and linter warnings about code smells. I see no issue with having the latter handled entirely by tools designed for the job.


Why not? Pretty sure it's used in a lot of places, so it does seem quite serious if a language.




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

Search: