Sign in to follow this  
Followers 0
aleph01

Generic coding questions

5 posts in this topic

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. :'(

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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. :'(

Share this post


Link to post
Share on other sites

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0