Page 1 of 2

i and j insteadusing x and y ?

Posted: Fri Mar 25, 2005 2:40 pm
by Ralf
since i am coding, i have ever used variables like following examples:

Code: Select all

for y = 0 to  480
  for x = 0 to 640
     ..code...
  next
next


for i = 0 to 100
  .. code...
next

but now when i study the web i found even more examples where people using i and j instead x and y... are i and j something like a stanard as used in following example? (i know, i could use any variable)

for j = 0 to  480     ; seems j stands for y in java/c/c++ !?
  for i = 0 to 640     ; seems i stands for x in jave/c/c++ !?
     ..code...
  next
next

Posted: Fri Mar 25, 2005 2:50 pm
by dell_jockey
Moin Ralf,

if you're iterating through a 2D picture space, using 'x' and 'y' makes perfectly sense.
I once read something about early programming days, where programmers couldn't really type with ten fingers. 'I' and 'J' were (and still are) close together on the keyboard and require only a single finger to type... If this is folklore or truth, I don't know, but is funny nonetheless.

Generally, give variables meaningful names, even those that are used as a counter in a loop. In two years' time, you still want to be able to read the code you wrote yourself, so make it clear what you intended. If you intend to distribute the code, it's even more important to clearly convey your intentions.

Tschüß

Re: i and j insteadusing x and y ?

Posted: Fri Mar 25, 2005 3:07 pm
by PB
In mathematics, X and Y have always been for left-right and up-down, and
Z is used for in-out (for 3D applications). I've never heard of I and J before.

Posted: Fri Mar 25, 2005 3:15 pm
by freak
I think the 'i' as a counter variable comes from 'index', but i'm not really sure about that.
My first ever book on programming (quickbasic :)) also used an 'i' in the examples
and i am still doing that today.

Some things are hard to change ;)

Posted: Fri Mar 25, 2005 4:02 pm
by blueb
I seem to remember 'i' stood for integer, because most loops were used as counters.


--blueb

Posted: Fri Mar 25, 2005 4:02 pm
by dell_jockey
Using 'i' for index counting is common indeed. However, it doesn't hurt to let the reader of your code know what it is, that you're counting there, so I recommend that you give these variables meaningful names as well. After all, one future day, you yourself might be that reader...

Posted: Fri Mar 25, 2005 4:12 pm
by Ralf
@dell_jockey: very interested... sure, i always try to use clear and selfexplained variables as long as i dont do any X,Y,Z stuff :)

@PB: You are right about the X,Y,Z - i thougt so too all the time! but there are really some sources on the web, wehre they use i and j for 2D operations too. It confused me a bit!

@freak: handshake! I use 'i' too for normal loops since i am coding!

@blueb: yes, i heared something about that some years ago! i stands for integer. If you do any 2D drawings, using Int would make sence but i was still wondering why the do not use something like iX iY !?

I use for all variables the first upper sign of its type and then its name! This makes coding for me much more easy and the source 1000 times more readable! For example:

Code: Select all

lRed = Point(x,y)                 ;   red is a long variable
dEastern = DIM name(x,y)   ;   Eastern is a DIM (normaly d = double)
fBeer = 2                            ;   Beer is a float
maybe this helped some... thanks

Posted: Fri Mar 25, 2005 4:13 pm
by traumatic
Yes, i,j and k stand for indexing variables.

Slightly OT but funny nevertheless:
http://mindprod.com/unmainnaming.html

Posted: Fri Mar 25, 2005 8:57 pm
by HeX0R
*lol*

Posted: Sat Mar 26, 2005 2:16 am
by freedimension
i, j, k and l, m, n are used very often as index-variables when calculating with matrices. As every 2, 3 or n-dimensional array can be seen as a matrix, it's no wonder, those letters are used that often. Keep in mind, that many developers from the early days are mathematicians.

Posted: Sat Mar 26, 2005 3:49 am
by griz
I use x,y and t all the time. Does anyone else use t?

Posted: Sat Mar 26, 2005 4:17 am
by Ralf
griz wrote:I use x,y and t all the time. Does anyone else use t?
yes, but i use this only when operating with images (manipulate) and for arrays. Else i use something like lPosX, lPosY for example ;)

Posted: Sat Mar 26, 2005 7:02 am
by Rescator
Another nice thing withh PureBasic is you can
use i.e x.l when using the variable in the code.
And if you do a mistake and type i.e x.w
the compiler will complain the type has allready been defined.
A nice way to avoid mistakes in critical code.

Posted: Sat Mar 26, 2005 7:57 am
by Xombie
I've been using iLoop and jLoop for god knows how long now. ^_^

Posted: Sat Mar 26, 2005 12:49 pm
by Tension
@traumatic

Good link. :lol:

Also good to know I'm keeping to a standard. :)