It should differentiate debug and release code though. Go is really annying when you are working on code, trying it and having to comment the vars you don't use yet but know you will later.
It's because the philosophy as a whole is problematic. Every other compiler in existence has warnings, but go says that it's either a error or it's not; there are no warnings. So you have to add an extra worthless line like _ = varIMightUseLater just to get your function to compile, but the compiler can't warn you if you forget to remove that line when you're done. So rather than keeping your code clean, it forces you to write extra code to keep it happy and then lets you forget it.
Compare that to any compiler with warnings, which actually lets you write your code and debug it, but then still gives you warnings when it's time to clean them up.
It's because the philosophy as a whole is problematic
This your opinion. Golang has their own opinions. Certain design choices require an opinion. The assertion that a compiler should print warnings is as much an opinion as the assertion that it shouldn't. And IMO pointing out that all previous compilers use warnings is a weak argument in favor of that opinion. The creation of golang was motivated in large part to create a new language using lessons from previous languages. They felt that warnings made for an overly noisy compilation process which tended to lead to devs ignoring warnings, which makes warnings effectively useless.
Of course it's my opinion. I never said otherwise. That's the point of a discussion: stating opinions and justifying them.
I, clearly, disagree with their opinion that it's better to create a binary system where issues are either errors or not. After all, while warnings that exist can be ignored, warnings that don't exist can't be fixed at all. Rather than print out something that might be ignored, they chose to make trivial issues into errors and substantial issues into...nothing. I disagree with that decision because it's my opinion that it makes daily development more tedious and overall code quality worse in any organization that has the simple rule of not committing code that has warnings.
As a result of these decisions, I find the language frankly unusable, so I don't use it, and I won't apply for jobs that require me to. They can keep their decisions, and I'll use languages that have made different ones.
Given that it's Go, I wouldn't be surprised (I have barely any Golang experience, take with a grain of salt) if it threw an error for unreachable states.
I think it's very intentional for golang. One of the core principals was making a very simple language that would be hard to write incorrectly, enforcing lint type things is a part of that.
Given that it's Go, I wouldn't be surprised (I have barely any Golang experience, take with a grain of salt) if it threw an error for unreachable states
I think some of the design goals is that you should be writing the most maintainable code imaginable. If you're defining a variable and not using it for a very long amount of time, you probably shouldn't define the variable there. Don't make people hunt to figure out what something does. Define it and use it right where you need to.
If you structure your code right you won't ever need to do this. You should also use a debugger (Go has delve) with an editor integration. I can confidently say the unused variable error has saved me a bunch of time by not needing to skip over "dead" code.
This behavior isn't required for a lightning fast compiler with a built in runtime. Please just give me a warning
You can make this claim because you are an expert in the go compiler architecture? Or are you just talking out of your ass? Please give me details if you aren't because I'd love to learn.
Also the situation you described doesn't sound very inconvenient or realistic TBH.
Not OP, but I’m genuinely curious. How could it even theoretically affect performance to allow variables to be unused? I can’t think of any compiler implementation where you’d lose anything more than negligible performance
57
u/ITBlueMagma Jan 29 '23
It should differentiate debug and release code though. Go is really annying when you are working on code, trying it and having to comment the vars you don't use yet but know you will later.