i and j insteadusing x and y ?

Everything else that doesn't fall into one of the other PB categories.
Ralf
Enthusiast
Enthusiast
Posts: 203
Joined: Fri May 30, 2003 1:29 pm
Location: Germany

i and j insteadusing x and y ?

Post 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
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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üß
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: i and j insteadusing x and y ?

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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 ;)
quidquid Latine dictum sit altum videtur
User avatar
blueb
Addict
Addict
Posts: 1118
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Post by blueb »

I seem to remember 'i' stood for integer, because most loops were used as counters.


--blueb
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post 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...
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Ralf
Enthusiast
Enthusiast
Posts: 203
Joined: Fri May 30, 2003 1:29 pm
Location: Germany

Post 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
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Yes, i,j and k stand for indexing variables.

Slightly OT but funny nevertheless:
http://mindprod.com/unmainnaming.html
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
HeX0R
Addict
Addict
Posts: 1219
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

*lol*
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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.
<°)))o><²³
User avatar
griz
Enthusiast
Enthusiast
Posts: 167
Joined: Sun Jun 29, 2003 7:32 pm
Location: Canada

Post by griz »

I use x,y and t all the time. Does anyone else use t?
Ralf
Enthusiast
Enthusiast
Posts: 203
Joined: Fri May 30, 2003 1:29 pm
Location: Germany

Post 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 ;)
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post by Xombie »

I've been using iLoop and jLoop for god knows how long now. ^_^
Tension
User
User
Posts: 29
Joined: Tue Mar 22, 2005 3:19 pm

Post by Tension »

@traumatic

Good link. :lol:

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