Results 1 to 5 of 5

Thread: declaring variables and not using them

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    59

    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!

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: declaring variables and not using them

    Possibly occupation of stack/heap space.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2018
    Posts
    59

    Re: declaring variables and not using them

    Quote Originally Posted by techgnome View Post
    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

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    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>

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width