Jump to content

Generic coding questions


Recommended Posts

I have a friend who does a lot of .vbs coding, although he is becoming fond of AutoIt after I introduced it to him recently.  However, I think he goes over-board in his usage of variables.  Is there any advantage to setting a string to a variable if the string is gong to be used only once in the script?  Example of his code:

$meteringSite   = "http://opac.forsythpl.org/launchcommand/hp/access.htm"
$meteringWindow = _IECreate($meteringSite, 0, 0, 1)

Example of how I would code this, given that this particular url is not going to be used again in the script:

$meteringWindow = _IECreate("http://opac.forsythpl.org/launchcommand/hp/access.htm", 0, 0, 1)

Both examples of code work.  I am just wondering if there is any advantage to using a variable in this situation.  Conversely, is there a disadvantage to not using a variable, or is it really just the coder's preference?

Thanks,

_aleph_

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

  • Moderators

I would point your friend to the Webster's definition of variable:

: able or likely to change or be changed : not always the same

And specifically under mathematics and computer science:

a quantity that can have any one of a set of values or a symbol that represents such a quantity

If it is not something that will be changed, or not located in more than one spot, the use of a variable would only serve for the purposes of readability.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks, JLogan3o13, I guess it's a matter of different strokes for different folks.  I just thought that referring to a variable might take some time.  Who knows when that microsecond might mean the difference between life and death, lol.

Meds.  They're not just for breakfast anymore. :'(

Link to comment
Share on other sites

  • Moderators

If it is a concern, I would say test it out for yourself, so you can show your friend how meaningful/negligable the differences are.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Another advantage, IMO, of using variables is this: say the script is several thousand, or even just hundreds of lines. With variables defined at the top of the script, it would be much easier to change them there if need be, rather than paging thru the script to find which functions use that data.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...