Page 1 of 1

[General Notice] Always avoid using one-character var names/

PostPosted: 15 Apr 2012, 14:10
by paul424
Always avoid using one-character variable names. Typping ' x , y , i , j ' make variables names editing proof in emacs [ and other editors ] , that is searching , substituting etc.
Now if you work with local code OD and see them just please rename them e.g : x->xx , y->yy, i->ii, j->jj. ; after some time we should get rid of that. Thanks.

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 13:12
by Bodsda
If your going to go ahead and change variable names, you might as well give them a meaningful name.
Changing i>ii doesn't solve the underlying problem

Bodsda

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 13:27
by svenskmand
@Bodsda: agreed

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 15:20
by oln
Loop variables can be ii, jj etc, but otherwise agreed.

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 21:48
by MCMic
Loop variable should be i, j, k…
It has always be this way, I see no reason to change.
I don't see how your editor would prevent you from editing one-char variables oO

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 22:01
by paul424
It seems that this thread is going to develop into nice "C++ Manual On Choosing Fancy Names For Local Variables Which Satisfy All Potential Code Team Members' .

In some larger block I had problem C-s -ing ( emacs search ) OLV* . Or there is meta-% for find and replace, etc. Editor won't stop me. But every letter 't' or 'i' would become a subject to mentioned macros, which is in long run cumbersome.






*One Letter Variable

Re: [General Notice] Always avoid using one-character var na

PostPosted: 22 May 2012, 22:50
by charlie
It's rather simple. If the loop is short and straightforward, why not use a single letter name?

If a variable is for wider user outside of a 5-10 line (max) loop, then you give it a descriptive name. It's all about common sense.

Re: [General Notice] Always avoid using one-character var na

PostPosted: 23 May 2012, 01:13
by Bodsda
I see no problems using single letter variable names for simple loop constructs, it is a habbit every programmer picks up very early on. Popular convention makes it acceptable, but its not preferred.

As for the find replace issue, why not just search for space<letter>space

Re: [General Notice] Always avoid using one-character var na

PostPosted: 23 May 2012, 12:15
by charlie
Bodsda {l Wrote}:I see no problems using single letter variable names for simple loop constructs, it is a habbit every programmer picks up very early on. Popular convention makes it acceptable, but its not preferred.

As for the find replace issue, why not just search for space<letter>space


That won't work as oft times these things don't have spaces either side of them e.g. somarray[i] or i++.

However, since the only time single character variables should be used is in a very small segment with a handful of appearances, copy/replace shouldn't matter.

Re: [General Notice] Always avoid using one-character var na

PostPosted: 26 May 2012, 16:14
by MCMic
paul424 {l Wrote}:It seems that this thread is going to develop into nice "C++ Manual On Choosing Fancy Names For Local Variables Which Satisfy All Potential Code Team Members' .

In some larger block I had problem C-s -ing ( emacs search ) OLV* . Or there is meta-% for find and replace, etc. Editor won't stop me. But every letter 't' or 'i' would become a subject to mentioned macros, which is in long run cumbersome.






*One Letter Variable

Hum, Geany, which uses grep for search, have an option "match full word only", I'm having a hard time believing emacs does not offer such a functionality.