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:

Recommended Answers

All 10 Replies

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.

Just be sure you have int target and not n target ;) If anything, it's good code practice to use descriptive variable names.

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.

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?

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. :)

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.

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!!

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).

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

For small simple loop variables, or very localized intermediate results, I may use single letter variables.

And, of course, for loops, the time-honored values of i,j,k,l left over from FORTRAN are the loop variables of choice.

n or t works with a local intermediate value, unless you are trying to explain the algorithm:

// swap two ints
int t = leftSide;
leftSide = rightSide;
rightSide = t;

But, in my opinion, any variable that lives over more than, say, 5 lines, should have a descriptive name or comment to make it's meaning obvious. Member variables of classes especially deserve meaningful names.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.