Do variable names affect a program?
it's really frustrating to be looking in my textbook and see something like
void apd(vector& a, int j, int n)
for (j = vector[a]; n > j; j--)
j++;
I would change it to something like
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:
SelArom
Junior Poster in Training
54 posts since Oct 2004
Reputation Points: 20
Solved Threads: 1
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.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
Just be sure you have int target and not n target ;) If anything, it's good code practice to use descriptive variable names.
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
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.
jasweb2002
Junior Poster in Training
56 posts since Sep 2004
Reputation Points: 11
Solved Threads: 2
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. :)
jasweb2002
Junior Poster in Training
56 posts since Sep 2004
Reputation Points: 11
Solved Threads: 2
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.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
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 :D
thanks again!!
SelArom
Junior Poster in Training
54 posts since Oct 2004
Reputation Points: 20
Solved Threads: 1
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).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
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
SelArom
Junior Poster in Training
54 posts since Oct 2004
Reputation Points: 20
Solved Threads: 1