-
Apr 26th, 2021, 10:48 AM
#1
Thread Starter
Member
declaring variables and not using them
HI,
One of the most common mistakes a programmer makes is declaring variables and not using them. But what is the negative effect of this, besides lines of code not used?
Reagrds!
-
Apr 26th, 2021, 10:52 AM
#2
Re: declaring variables and not using them
Possibly occupation of stack/heap space.
-tg
-
Apr 26th, 2021, 10:56 AM
#3
Thread Starter
Member
Re: declaring variables and not using them
Originally Posted by techgnome
Possibly occupation of stack/heap space.
-tg
I appreciate your response! Very kind of you.
Could you describe a little more about this, showing some possible bad scenarios? For example: Slowness, crashes, etc.
I'm sorry for my bad English
-
Apr 26th, 2021, 11:02 AM
#4
Re: declaring variables and not using them
It will surely not affect final executable in any way (will be optimized away) but allowing code rot early in the project lifetime will be the root to more problems further in time.
https://medium.com/@learnstuff.io/br...t-bef627a1ce99
MZ-Tools has a very cheap code linter under its Review Source Code menu option. This works on current module, on whole current project or on all project in the loaded project group.
For something like aivosto's Project Analyzer style of analysis a full blow VB6 parser is needed (with high fidelity too) which MZ-Tools does not have apparently, judging by the number of false positives it sometimes reports.
cheers,
</wqw>
-
Apr 26th, 2021, 11:07 AM
#5
Re: declaring variables and not using them
It doesn't work like that. Declaring a variable and not using it isn't necessarily going to slow something down. At least not one. Or two. Or three. Or even a couple dozen. What it does lead to is bad programming practices. Once you think it's OK to do it here, then you think it's OK to do it there, and the next thing you know you have what's known as a memory leak. That's when your app is taking more memory than it should. In this day, it's less of a problem since memory is in abundance and is cheap. But back in the day, it wasn't cheap and it wasn't in abundance. You had to be extraordinarily cautious about your variables and only create those that you actually used. Or, yeah, you'd bust the memory of the system and you could get a "System out of Memory" error. Today that's less of a worry. But the lessons of the old lead to certain practices that are still just considered good form today. And one of those is to only create that which you need. Don't leave a bunch of unused variables lying about. It can also create noise, making it harder for other developers that come along after you reading your code harder to figure out what the code actually does. If I see a variable called PIValue in some code somewhere, I expect it to be set to the value of PI at some point... and when it doesn't... will wonder why it was even in there.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|