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

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

Postby paul424 » 15 Apr 2012, 14:10

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.
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

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

Postby Bodsda » 22 May 2012, 13:12

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
User avatar
Bodsda
OD Moderator
 
Posts: 195
Joined: 18 Feb 2010, 08:19

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

Postby svenskmand » 22 May 2012, 13:27

@Bodsda: agreed
Jamendo.com - The best music store on the net, uses CC licenses.
User avatar
svenskmand
OD Moderator
 
Posts: 1850
Joined: 09 Dec 2009, 00:07
Location: Denmark

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

Postby oln » 22 May 2012, 15:20

Loop variables can be ii, jj etc, but otherwise agreed.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

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

Postby MCMic » 22 May 2012, 21:48

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
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

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

Postby paul424 » 22 May 2012, 22:01

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
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

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

Postby charlie » 22 May 2012, 22:50

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.
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

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

Postby Bodsda » 23 May 2012, 01:13

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
User avatar
Bodsda
OD Moderator
 
Posts: 195
Joined: 18 Feb 2010, 08:19

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

Postby charlie » 23 May 2012, 12:15

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.
Free Gamer - it's the dogz
Vexi - web UI platform
User avatar
charlie
Global Moderator
 
Posts: 2131
Joined: 02 Dec 2009, 11:56
Location: Manchester, UK

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

Postby MCMic » 26 May 2012, 16:14

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.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Who is online

Users browsing this forum: No registered users and 1 guest