When writing quick, get-er-done scripts, I often overwrite variable names once I don’t need them anymore. Is this bad? It saves memory, in the same way recycling a soda can saves the planet.
When writing quick, get-er-done scripts, I often overwrite variable names once I don’t need
Share
How does it save memory to overwrite a variable as opposed to disposing of it properly and declaring a new one. Do you have any experience with the mechanics of assembly? I believe the only thing you save by doing it your way is typing. Code readability suffers when you don’t choose unique variables as you get further down the script.
Take for example a book that reuses page 1 all the way through to the page of a 300 page book. How easy would it be to recall your position?
In reference to your comparison of reusing variables and recycling. Variables are relative spaces of memory that are dissipated completely as though they never existed upon destruction, where as plastics and paper will always leave some sort of footprint even if it is in the form of a physical shift, such as a solid to a gas.
I would recommend declaring only the amount of variables needed to get the job done, but as many as it takes to improve code readability. Unless there is some alternative motivation.
I look at variables like plates at the buffet, once your done… Get a new one.