3 ms·
The way I deal with this in my language, which also bans unused variables, is simple: I delete the unused variable or I use it. My workflow is probably very di
by norir 2y ago
The way I deal with this in my language, which also bans unused variables, is simple: I delete the unused variable or I use it.
My workflow is probably very different from yours I'm guessing. I have my editor configured to save on every keystroke and I have a watch process that then recompiles my code. I pretty much never manually compile. My compiler is sufficiently fast that I almost never wait more than 1 second to build and run my code. I notice every error immediately and fix them as they arise. This is what I am talking about with discipline. I never allow my code to get into an unexpectedly broken state and don't need a linter since I just make the compiler as strict as I would make the linter. This ultimately simplifies both the compiler and the build pipeline.
These are all huge upsides for me. The cost of occasionally deleting a definition and then restoring it are for me minor compared to the cost of, say, writing a separate linter or adding feature flags to the compiler (the latter of which doesn't fit into my workflow anyway since I auto compile).
- xigoi 2y agoThe problem is that in order to delete an unused variable, you may need to delete a huge chunk of code which would be useful later when you want to actually use the variable.
- em-bee 2y agocan you give an example please? i can't imagine how any section of code would be affected by removing an unused variable. if the code reference the variable, it would be used. if it doesn't, then why would you have to delete it?
- xigoi 2y agoIn pseudocode: a = input() b = f(a) c = g(b) d = h(c) If you delete the unused variable d, then c will be unused, so you’ll have to delete it too. Iterating this, you will end up deleting the entire code.
- throwawaymaths 2y agoYou could: - comment it out - use git - use ctrl-z
- xigoi 2y agoHaving to do that after every small change really breaks the flow.
- throwawaymaths 2y agoYeah ok. Overstated. in reality this will be at most 1/20th if your changes. Maybe 1/6 if you're debugging.
- alpaca128 2y agoOr alternatively the compiler could just not force me to do any of those things.