943,981 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 3513
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 14th, 2004
1

Do variable names affect a program?

Expand Post »
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:
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Nov 14th, 2004
1

Re: Do variable names affect a program?

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.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
Nov 14th, 2004
0

Re: Do variable names affect a program?

Just be sure you have int target and not n target If anything, it's good code practice to use descriptive variable names.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Nov 14th, 2004
1

Re: Do variable names affect a program?

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.
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004
Nov 14th, 2004
0

Re: Do variable names affect a program?

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?
Reputation Points: 113
Solved Threads: 3
Posting Whiz
Asif_NSU is offline Offline
353 posts
since Apr 2004
Nov 15th, 2004
0

Re: Do variable names affect a program?

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.
Reputation Points: 11
Solved Threads: 2
Junior Poster in Training
jasweb2002 is offline Offline
56 posts
since Sep 2004
Nov 15th, 2004
0

Re: Do variable names affect a program?

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 15th, 2004
0

Re: Do variable names affect a program?

Quote 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!!
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004
Nov 15th, 2004
0

Re: Do variable names affect a program?

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).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 15th, 2004
0

Re: Do variable names affect a program?

Quote 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
Reputation Points: 20
Solved Threads: 1
Junior Poster in Training
SelArom is offline Offline
54 posts
since Oct 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: writing a simple cat program
Next Thread in C Forum Timeline: sorting and functions/structures





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC