This is why I always write my methods from bottom to top. This way I've always got a return statement and I use my variables before they are even declared.
IDE is one thing, Go refuses to compile. Like calm down, I'm going to use it in a second. Just let me test the basics of my new method before I start using this variable.
Or every time you add or remove a printf it refuses to compile until you remove that unused import. Please just fuck off.
Yeah I think it's trauma due to C/C++'s awful warning system, where you need a gazillion warnings for all the flaws in the language but because there are a gazillion of them and some are quite noisy and false positives prone, it's extremely common to ignore them. Even worse, even the deadly no-brainer ones (e.g. not returning something from a function that says it will) tend to be off by default, which means it is common to release code that triggers some warnings.
Finally C/C++ doesn't have a good packaging story so you'll pretty much always see warnings from third party code in your compilations, leading you to ignore warnings even more.
Based on that, it's very easy to see why the Go people said "no warnings!". An unused variable should definitely be at least a warning so they have no choice but to make it an error.
I think Rust has proven that it was the wrong decision though. When you have proper packaging support (as Go does), it's trivial to suppress warnings in third party code, and so people don't ignore warnings. Also it's a modern language so you don't need to warn for the mistakes the language made (like case fall through, octal literals) because hopefully you didn't make any (or at least as many).
IDE: Oh! You mean farfignewton right? I found that in some completely unrelated library you didn't write. Allow me complete that for you while you're not paying attention.
I try my best to make my IDEs follow the principal that I should be able to type without looking at the screen, but apparently IDEs are really invested in return accepting completions to the point it's often not configurable even when every other key is.
I start writing the implementation and get the "variable not defined" error and then let the ide add the declaration. It's less keys to press and misspell.
Imagine lint running on format and your linter removing unused variables: you start typing, hit format by muscle memory before using the variable. Rinse and repeat.
I recently started poking with Vue, For the most part when it comes to webapps I've mostly worked with React, Blazor, and a touch of Svelte. The linter is so aggressive. I start defining a method and it instantly goes "IT DOESN'T RETURN ANYTHING!!"
Okay, thanks! I literally just defined the return type!
It's probably gonna be optimized out by the compiler. However, linters will mark it for you, since it suggests that you actually wanted to do something with that variable and forgot about it after declaration.
... Or it can be removed to reduce visual noise once it's not necessary anymore after refactoring.
Lets say you use a variable named abcd in your function. And a variable named abcb in a for loop inside the same function. But because reasons you mistakenly use abcd inside that loop and modify the wrong variable, so that your code sometimes doesnt work properly.
It's to prevent mistakes like that.
A similar thing is to use const when the variable is not modified.
How do you mean? You can't type a word without using it in a word processor. Once the word is typed out it's been used. Variables need to be declared then used so 2 separate steps.
What do you mean? Variables do not necessarily need to be used, you can allocate memory for some value and initialise it but then simply don't do anything with it.