Recommended Posts

Yeah, you need longer variable names. I suggest:

pi_thing instead of p (since pi may cause confusion).

Share on other sites
slicer4ever    6769

int l,dijk=di+nx*(dj+oy*dk),dijkl,dijkr,ima=step_div(dk-ez,nz);
int qj=dj+step_int(-ima*byz*ysp),qjdiv=step_div(qj-ey,ny);
int qi=di+step_int((-ima*bxz-qjdiv*bxy)*xsp),qidiv=step_div(qi,nx);
int fi=qi-qidiv*nx,fj=qj-qjdiv*ny,fijk=fi+nx*(fj+oy*(dk-ima*nz)),fijk2;
double disy=ima*byz+qjdiv*by,switchy=(dj-ey)*boxy-ima*byz-qjdiv*by;
double disx=ima*bxz+qjdiv*bxy+qidiv*bx,switchx=di*boxx-ima*bxz-qjdiv*bxy-qidiv*bx;
double switchx2,disxl,disxr,disx2,disxr2;

/*
so you have created qj, qi, and more badly named
crap at the top of your function... again.
*/


O man, that's just....I don't even know. is their actually comma separated code in that? and a random variable doing...nothing on the 4th line?
that student needs to get a talking to.

I think with things like visual assist x, and code-completion tabbing. i've pretty much stopped doing this practice(although i never did it very much anyway). I like to use full names for things most of the time, just because of the fact that it looks nicer at the end of the day.

edit: that's actually making me a bit sick looking at it, i'm ganna go lie down for a bit now. Edited by slicer4ever

Share on other sites
int l;


is especially nice, especially if you use a font which makes l and 1 look very similar.

EDIT: Obviously it should be called lambda

Share on other sites
Nercury    812

a random variable doing...nothing on the 4th line?

Well to be fair I have hand-picked the worst from this code, and this is just a beginning of the method.

Share on other sites

Oh sure it is more compact. And that is NOT a good thing. Of COURSE I can figure out what it all means eventually, I am not THAT stupid. But it is not the point.

I can't and I'm not that stupid (OK, I am, but still). That thing is just plain unreadable, I have an easier time reading blobs from hex editors... I'd kick immediately anybody who came up with code like that. The only place where I'd tolerate something like that is for stuff like 4k demoscene compos or something similar (and where the 4k limit applies on the source code, e.g. javascript demos and such).

Also oh god that last link... WHY (?°?°)?? ???

Share on other sites
Bacterius    13165
remap(ai,aj,ak,ci,cj,ck,x,y,z,ijk);
vc.find_voronoi_cell(x,y,z,ci,cj,ck,ijk,w,mrs);
This code has to be generated by a machine. Or he did a search & replace at the very end. No sane human can make sense of this.

Share on other sites

int l,dijk=di+nx*(dj+oy*dk),dijkl,dijkr,ima=step_div(dk-ez,nz);
int qj=dj+step_int(-ima*byz*ysp),qjdiv=step_div(qj-ey,ny);
int qi=di+step_int((-ima*bxz-qjdiv*bxy)*xsp),qidiv=step_div(qi,nx);
int fi=qi-qidiv*nx,fj=qj-qjdiv*ny,fijk=fi+nx*(fj+oy*(dk-ima*nz)),fijk2;
double disy=ima*byz+qjdiv*by,switchy=(dj-ey)*boxy-ima*byz-qjdiv*by;
double disx=ima*bxz+qjdiv*bxy+qidiv*bx,switchx=di*boxx-ima*bxz-qjdiv*bxy-qidiv*bx;
double switchx2,disxl,disxr,disx2,disxr2;

/*
so you have created qj, qi, and more badly named
crap at the top of your function... again.
*/


What the?  What human could just look at that and know exactly what is going on?  If I had to read crap like that every day I'd just quit programming.  I don't think it'd be worth the pain every day.

Share on other sites
alh420    5995

Makes me remember my best friend in highschool.

I don't think I ever say him use a variable name with more then 4 characters. mostly 3.

I guess it looked good together with the embedded asm he was writing.

He also didn't like to use circuit boards when building his electronics, because they were a waste of time and space.

Instead he build his circuits with all air-connections, in 3D... (yes, they did work, perfectly)

He's now pretty far into his academic career :P

Share on other sites
slicer4ever    6769

struct Vertex
{
int index;
float x;
float y;
float z;
Vertex* next;
};
{
while(p)
{
if(p->index == index)
return p->x;
p = p->next;
}
return 0;
}
{
while(p)
{
if(p->index == index)
return p->y;
p = p->next;
}
return 0;
}
{
while(p)
{
if(p->index == index)
return p->z;
p = p->next;
}
return 0;
}
struct Face
{
int index;
int i0;
int i1;
int i2;
Face* next;
};
{
while(f)
{
if(f->index == index)
return f->i0;
f = f->next;
}
return 0;
}
{
while(f)
{
if(f->index == index)
return f->i1;
f = f->next;
}
return 0;
}
{
while(f)
{
if(f->index == index)
return f->i2;
f = f->next;
}
return 0;
}
void drawMesh(Face* f, Vertex* v, int n)
{
glBegin(GL_TRIANGLES);
for(int i=0;i<n;++i)
{
glVertex3f(getX(getV0(f,i)), getY(getV0(f,i)), getZ(getV0(f,i)));
glVertex3f(getX(getV1(f,i)), getY(getV1(f,i)), getZ(getV1(f,i)));
glVertex3f(getX(getV2(f,i)), getY(getV2(f,i)), getZ(getV2(f,i)));
}
glEnd();
}

o god, that's horrid, and so incredibly inefficient, I don't even know.

Share on other sites
RobTheBloke    2553

o god, that's horrid, and so incredibly inefficient, I don't even know.

It was all like that, but his exam marking was his worst offence. He'd often fail 50% of a year group, and barely pass the rest. All because he had absolutely no clue. If the students had me as a second marker, they were lucky. Some other 2nd markers weren't as diligant though :(

Why do you need to name your class fields as c, cc, d, e? What the hell are you trying to obfuscate?

Most lecturers are generally pretty level headed, and do try to keep their code clean and readable. The more research based they are however, the more chance there is for strangeness to creep in. Academic research can be quite an isolating experience, so you don't often have people around to bounce ideas off, which does tend to encourage people to slip into some really bizarre habits.

There is also a tendancy for some senior academics to stick their name on top any paper from any student they are supervising. This experience can make a junior researcher quite paranoid, and overly protective of their work. Once they've got a Phd, often this paranoia doesn't leave the academic, but simply becomes much more engrained. Maintaining secrecy, and deliberately obfuscating code, is not uncommon in the academic world as a result.....

Share on other sites

I also imagine that for those with a heavy maths background they will try to name program variables as if they were doing so in an equation out of custom (since in equations everything is a letter and maybe a subscript).

Share on other sites
Bacterius    13165

I also imagine that for those with a heavy maths background they will try to name program variables as if they were doing so in an equation out of custom (since in equations everything is a letter and maybe a subscript).

True, but in general equation variables are named sensibly. I have trouble conceiving an equation mapping to this:

step_int((-ima*bxz-qjdiv*bxy)*xsp)


Nah it just looks like someone trying to use 1-letter variables, running out, moving on to 2-letter variables, running out, and so on.

Reasonable variable names are descriptive stuff like "delta", "x_prime", "du", and so on. But having multiple variables called "disx", "disy", "disxl", "disxr", "disx2", "disxr2" is unreasonable. It's insane. You have to look up their meaning to invoke them when needed, unless you know the code by heart (which should not be the case for even remotely self-documenting code). It might be good for a code-and-forget kind of project or library, but good luck maintaining this.

PS: or excessive precomputation, maybe.

Edited by Bacterius

Khatharr    8812

"du"?

Share on other sites
Bacterius    13165

"du"?

Change in the variable "u". For a physics library I can see that coming up and people would know what it is referring to (if the "u" variable is clear, of course). Maybe "dt" is a better example (change in time, and the ubiquitous update(double dt) function signature)

Edited by Bacterius

Share on other sites
Khatharr    8812

Oh, you mean delta_u.

Share on other sites
Bacterius    13165

Oh, you mean delta_u.

Nah, too long, "du" is used everywhere in mathematics as notation so it's a perfect candidate as a variable name. On the other hand, more complicated rates of change could use better variable names, "d3udv3" doesn't work out so well

Share on other sites
Krohm    5031

I fully endorse this product and/or service.

Share on other sites
Tom KQT    1704

I wouldn't say that using p as a name for verticle position variable is a coding horror, especially if it is some particle class with position (p), velocity (v) and acceleration (a), where the meaning is quite obvious. I personaly would use at least pos, vel, acc, but probably not the full text. Acceleration is so long to write...

Share on other sites
ZebraQuake    131

Even "p" as the position of a particle is ambiguous - it could easily be momentum (which is denoted as "p"). I've always despised single-letter variables (Volume? Velocity? Voltage? Acceleration? Amperes? Area?) even when dealing with mathematics. Walking into programming where it's [i]expected[/i] that variable names be descriptive with such behavior is, in my opinion, inexcusable. I mean, "vel" is already a massive improvement over "v" (likewise with "pos" and such) -_-

Share on other sites
Azaral    467

Yes, I hate trying to read code where they use short hand variable names.

The human brain is wired to instantly recognize words it knows. You read number all over the place. When you see number even if it is not in the correct order, you will be able to recognize it as such.

Writing out words instead of short handing them makes the code SOOO much easier to read.

"Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is taht the frist and lsat ltteers be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe."

That right there should be evidence enough for people to use FULL AND MEANING FULL words for their code. Is it really that much more effort to type a few extra letters.

Share on other sites
Bacterius    13165

That right there should be evidence enough for people to use FULL AND MEANING FULL words for their code. Is it really that much more effort to type a few extra letters.

Better yet - now we can randomize variable names without impeding code readability, as lnog as the frsit and lsat cahracetrs are in the rghit palce

That said there is an anti-argument to this - ridiculously long variable and function names lead to extremely long code lines (think business java code with getCustomerFormAndIDFileSecureTransactionDBConcurrent() methods) which are difficult to read, not to mention print. So a balance needs to be achieved somehow.

Edited by Bacterius

Share on other sites
Azaral    467

That right there should be evidence enough for people to use FULL AND MEANING FULL words for their code. Is it really that much more effort to type a few extra letters.

Better yet - now we can randomize variable names without impeding code readability, as lnog as the frsit and lsat cahracetrs are in the rghit palce

That said there is an anti-argument to this - ridiculously long variable and function names lead to extremely long code lines (think business java code with getCustomerFormAndIDFileSecureTransactionDBConcurrent() methods) which are difficult to read, not to mention print. So a balance needs to be achieved somehow.

Heh. They COULD be random, if you're happy with your code not compiling

And yeah, obviously if its TOO long then you've got a problem too.

Create an account

Register a new account