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.
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.
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.
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!
As someone who's been a software developer for over a decade and in IT even longer, I still don't use vi/vim for anything other than when crontabs have it set as the editor.
Honestly if you don’t use vim motions in your ide of choice, you’re missing out big time. Being able to do things like “Delete everything inside these parentheses”. di( or “wrap this line and the two lines below r in a pair of {}” ys2j{ , or “swap this parameter with the next one” cxia]a. with a single shortcut is game changing.
Even just being able to repeat an action a number of times is ridiculously useful. I use relative line numbers, so I can see how many lines away a target is and just go “I need to move down 17 lines” and hit 17j.
Absolutely insane how much quicker it is too do stuff with vim motions than ctrl-shift-arrows and the like
That's really neat, but I don't think I do that often enough to really make the performance hit of learning a whole new thing and memorizing keyboard shortcuts and commands worth it. I don't find myself refactoring code a ton, especially after moving to a more TDD-like model.
It’s less about refactoring and more about navigation of your code while editing. Ever wanted to delete a single word? daw deletes the word your cursor is currently in. How about "copy everything up to (but not including) the nearest “D” on the current line? yfD.
The whole point is that editing code in the middle of writing it, not just refactoring it, is immensely faster.
programmer_humor
Active
This magazine is from a federated server and may be incomplete. Browse more on the original instance.