Making code unmaintainable...

Miscellaneous Forums/General Discussion/Making code unmaintainable...

I'm sure a whole load of you hav eseen this already, but i found it funny:

http://mindprod.com/jgloss/unmainnaming.html

Doesn't sound to far away from my very first ventures into programming :) - cramming as much as you could into one line, single letter variables so you could save as much memory as possible.

Ahh, them were the days where starting a new line of code would take a few valuable bytes of memory away.

I remember interviewing a programmer who was extremely proud of his coding, so proud he brought a huge A4 folder of code listings with him.

His CV was pretty good on paper, but looking at his code there was things similar to this (which was involved in controlling some electrical devices).

  for enterprise = 1 to spock
     kirk = kirk + 1
     if kirk = 1 then scotty = 1
     if kirk = 2 then scotty = 2
     if scotty > tribble then beammeup(scotty)
  next

I kid you not!

When questioned on how he planned and started a project, he said he first came up with a theme (no prizes for the theme above), then named everything based on that theme..

Unless you havn't guessed, he didn't get the job!

I hope you kicked him down the stairs.

If kirk is a command variable and scotty is an engine flag...


Do you remember on the spectrum when it took less memory to set a single letter variable and use it three times than to have numbers.

Edit: Thats probably still true isnt it? But I dont care anymore

LOL, that's kind of cool in a wacky way!

Very nice, but I will still use:

for n=1 to 234
do whatever
next

Just because BG didn't finish school doesn't mean we have to use i instead of n. n mathematicaly is more sound for this kind of interaction, and if this is not accepted. I yhe old speccy it was:

10 FOR n=1 TO 10
20 ...
30 NEXT n

n being in the NEXT key of the keyboard.

Enough said. :D

Sadly, having programmed in fortran for a while,

for i = 1 to 100

is firmly fixed in my coding style ;)

I never use 1 letter variables... Everything I do means something... I rarely bother commenting becase all my Variables make enough sense on their own..... Only when the language itself is unclear do I comment.

i comment every so often when i am unsure if i will remember what something does or if i have 2 variable names that i could mix up

also i use underscores a lot

if used in a sensible way, one letter vars add to simplicity
and readability of code...it really depends on the context.

var=othervar[i];

most people will use this approach...it makes sense, i is the
index used to deref a value in an array. n is also commonly
used here, nth index...

jst as, x and y are often used index 2d arrays..

it doesnt really matter, but people tend to relate single
letter vars to temp locals..scratch vars..

for(int i=0;i<gvec_len;++i)gvec[i]*=gvec[i];

another common use may be..

enum{X,Y,Z};

vec[X]=0.5f;
vec[Y]=0.5f;
vec[Z]=0;

then again, perhaps im totally wrong :] ;)

I'm not the best coder in the world. At all, but I use the same variables in ALL of my projects:

SCX:INT=Screen Width
SCY:INT=Screen Height

For N = 1 to 10
     'BlahBlah!
Next

For X = 1 to 10
     For Y = 1 to 10
          'Graph or 2D array stuff
     Next
Next


haha you're using N as your for loop variable (I used ot on the Spectrum too). It should be I ;-) N is normall the top of the range for example 1 to N (in maths). There's nothing wrong with X and Y though...I tend to use W and H for width and Height and SCX and SCY to me might mean the top left coords of the screen (for scrolling).

All my 1-dimensional (for-)loop vars are: t n i a k t2

All my 2-dimensional (for-)loop vars are: x y xx yy x2 y2

And using single- (or sometimes double-)char isn't an issue, as long as keep using the same chars everytime.

Small vars often increases readability, if varnames are too long the whole screen is filled with vars and the commands get spreaded a bit too much to my liking, when commands are too far away you could loose the focus on them.

And ofcourse, in an IDE without code/var-completion, singlechar vars are faster to type.. :P

yeah single vars or small works for local variables rock, but not for globals. I use single vars for type fields often, stuff like x, y, w, h, but longer names for stuff like power, counter etc.

I have to disagree with you all... Long var names are prefered as long as they are descriptive enough... Course I code a lot of RPG stuff... and well..

WD[CW[PC[MC]]]


is impossible to read... while..

Weapon_DMG[Characters_Weapon[Player_Characters[Moving_Character]]]


Now it is clear it is the DMG of the weapon that the character who is currently moving is holding.

I think this extends to all levels...

For example.

A loop should be given a proper var name to define what it is counting...


Full = 29
Stuffed = 80

for Pie_Slices = 1 To 100
  Bobby = Pie_Slices
  If Bobby == Full
     Print "Bobby is Full"
  If Bobby == Stuffed
     Print "Bobby is Stuffed"
End_For
Print "Bobby died from eating too much Pie"
  


Doesn't make any real sense... but you see...


For Battle_Character = 1 To 10
   Character_HP[Battle_Character] = Character_Max_HP[Battle_Character]
End_For



Ok... I'm done.

All my loops are F

For f= 1 to ..

F being the Key for "For" on the spectrum, OuterLoop f, nextLoop G, h etc

@DampeS8N...
The point is not that long var names are wrong, but that
there is nothing wrong with using short names.

"WD[CW[PC[MC]]]" - this is clearly an extreme example.


this...

enum{X,Y,Z};

vec[X]=0.5f;
vec[Y]=0.5f;
vec[Z]=0;

is not hard to read... i was talking about sensible label
usage, not whether one is better than the other..

you will also note that it is quite common to deref vars
before they are used to index arrays to prevent the
following type of expression.
var=[[[[[]]]]];

passed so may levels of indirection, its nearly always
awkward to figure out what something is really doing,
long labels do not always help..

anyway - its mostly opinion...and your opinion is no less
valid that my own... so ill shutup :)

I use long for most things but short locally like I said:

For i = 0 to MAX_THINGS-1
    Things[i] = LoadImage("image"+i)
Next


I'm not going to bother renaming i as ThingCount or something.

yeah, if you always use the same vars for counters, you simply *know* they're counters .. no need to have a long name then, only to say they're counters.

im guilty of using stupid variable names

for loops will often be woop, cat or dog.

Sure you might know that i, n or f are counters, but counters for what? I'm with DampeS8N on this one. Only short variables names I ever really use are x, y and z for coordinates.