Do variable names affect a program?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2004
Posts: 54
Reputation: SelArom is an unknown quantity at this point 
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Junior Poster in Training

Do variable names affect a program?

 
1
  #1
Nov 14th, 2004
it's really frustrating to be looking in my textbook and see something like

  1. void apd(vector& a, int j, int n)
  2. for (j = vector[a]; n > j; j--)
  3. j++;

I would change it to something like
  1. void functionName(vector& theArray, int position, n target)

that way I know what the heck I am doing! does this negatively impact my program in a) an insignificant way, b) a huge way, or c) not at all?

thanks!

p.s. haha i'm a junior techie that sounds just terrible :cheesy:
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Do variable names affect a program?

 
1
  #2
Nov 14th, 2004
I would figure so long as it's consistent in your program, and you're not using a "reserved word" for your language, you'll be in good shape.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,043
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Re: Do variable names affect a program?

 
0
  #3
Nov 14th, 2004
Just be sure you have int target and not n target If anything, it's good code practice to use descriptive variable names.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 56
Reputation: jasweb2002 is an unknown quantity at this point 
Solved Threads: 2
jasweb2002 jasweb2002 is offline Offline
Junior Poster in Training

Re: Do variable names affect a program?

 
1
  #4
Nov 14th, 2004
Just curious, was that code segment from the book or did you just make it up without thinking about the logic? Just looks like a goofy piece of code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 353
Reputation: Asif_NSU is on a distinguished road 
Solved Threads: 2
Asif_NSU's Avatar
Asif_NSU Asif_NSU is offline Offline
Posting Whiz

Re: Do variable names affect a program?

 
0
  #5
Nov 14th, 2004
I am not sure, but what i get from SelArom's post is that he wants to know if a variable name has any impact on the program i.e if i use
int this_is_just_for_fun_and_to_waste_ur_precious_time;
instead of
int a;
and do so for over a hundred variable that i might have in my program--will it make any difference?
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 56
Reputation: jasweb2002 is an unknown quantity at this point 
Solved Threads: 2
jasweb2002 jasweb2002 is offline Offline
Junior Poster in Training

Re: Do variable names affect a program?

 
0
  #6
Nov 15th, 2004
No, variable names can be whatever you want. If you want to can choose to use only one letter variable names. Or you could have variable names that look similiar to previous post. Or you can use a combination, name them whatever you want. Think of it as naming children.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Do variable names affect a program?

 
0
  #7
Nov 15th, 2004
Variable names make a difference in how easy your program is to maintain and how many bugs you'll introduce writing it.
They'll also affect the way your colleagues will treat you, whether you'll get a pizza or a one way trip out the 3rd floor window during the next crunch session :eek:

They won't matter a thing after the compiler is through with it.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 54
Reputation: SelArom is an unknown quantity at this point 
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Junior Poster in Training

Re: Do variable names affect a program?

 
0
  #8
Nov 15th, 2004
Originally Posted by jwenting
Variable names make a difference in how easy your program is to maintain and how many bugs you'll introduce writing it.
They'll also affect the way your colleagues will treat you, whether you'll get a pizza or a one way trip out the 3rd floor window during the next crunch session :eek:

They won't matter a thing after the compiler is through with it.
wow thank you for all the useful information everyone! Yes, I wanted to know if by picking long, descriptive names if my program would suffer somehow. It seems everywhere I look people just use one letter variable names. I guess if you're that good more power to ya but I like to know what i'm lookin at =)

oh and yeah, I would use int target, not n target, lousy keyboard it was his fault. the code segment wasn't exactly from the book, I kinda jumbled it together to show you how hard it is for me to follow when they don't use damn descriptive variable names. I spend enough time in front of the computer without having to think of an example that makes logical sense

thanks again!!
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Do variable names affect a program?

 
0
  #9
Nov 15th, 2004
one letter variables can be helpful, for example as loop iterators where they really have no meaning except as a simple counter and have a very limited lifespan (when you use for (int i=0;i<10;i++) everyone knows what i does, when you declare int i asa a global and first use it 100 lines later it get hard to read).
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 54
Reputation: SelArom is an unknown quantity at this point 
Solved Threads: 1
SelArom's Avatar
SelArom SelArom is offline Offline
Junior Poster in Training

Re: Do variable names affect a program?

 
0
  #10
Nov 15th, 2004
Originally Posted by jwenting
one letter variables can be helpful, for example as loop iterators where they really have no meaning except as a simple counter and have a very limited lifespan (when you use for (int i=0;i<10;i++) everyone knows what i does, when you declare int i asa a global and first use it 100 lines later it get hard to read).
yeah I do that myself, as you said, for a short lifespan. but jeez some people use i and j and n and I don't know what the hell they're talking about. It's like talking in acronyms. just say the phrase man, the extra half a second won't kill you. :mrgreen: thanks again
You are somebody, just as I am somebody... but in the end, when you REALLY think about it, we are all nobody...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC