Academia

Started by
35 comments, last by slicer4ever 10 years, 5 months ago
Academia. Full of brilliant people. However, more often than not, when it comes to programming, they produce the hardest code to read EVER.

Why do you need to name your class fields as c, cc, d, e? What the hell are you trying to obfuscate? And no, that wall of well-aligned comments is not a solution. And please, stop teaching students variables by naming them a, b, c, d. Please. Just. Stop. Later they become professors who can not produce a readable code.

You probably think that your code looks good because it nicely fits in a box. I know that you were making pixel shaders before I was even born, but you are wrong.

Another example:
/** A two dimensional array holding particle positions. For the
 * derived container_poly class, this also holds particle
 * radii. */
double **p;


Why don't you just name it "positions"? What are you trying to save? Certainly not a compiled binary size, because the name does not matter there. Are you producing that extremely complicated code inside this class SO FAST that you can not type a full name of "positions" variable every time it is needed? No wonder you end up with your method contents looking like this:



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.
*/


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.


What if you have another friggin' class where "p" means "pizza"? Why do you have to remember to mentally switch from "oh, I am working with particle class so "p" means "positions"" to "oh this is pizza delivery class so "p" means "pizza"".

But yeah, I understand that you won't encounter "pizza" anywhere, because you have never worked with a huge code base where you simply can not remember everything.

P.S. This little rant was not intended as a good critique. It just sometimes gets to me smile.png
Advertisement

Yeah, you need longer variable names. I suggest:

alpha instead of a

beta instead of b

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley


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.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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.

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 (?°?°)?? ???

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


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.

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

I was a demonstrator / lecturer for a few years, and had to demonstrate for one particularly terrible lecturer. Most of his code was so far beyond bad it simply wasn't funny. The one code example he gave to students that sticks out most, was his OBJ loading & rendering code. I've ommitted support for the normals and UVs, but I think you get the idea.....

struct Vertex
{
   int index;
   float x;
   float y;
   float z;
   Vertex* next;
};
float getX(Vertex* head, int index)
{
   Vertex* p = head;
   while(p)
   {
      if(p->index == index)
         return p->x;
      p = p->next;
   }
   return 0;
}
float getY(Vertex* head, int index)
{
   Vertex* p = head;
   while(p)
   {
      if(p->index == index)
         return p->y;
      p = p->next;
   }
   return 0;
}
float getZ(Vertex* head, int index)
{
   Vertex* p = head;
   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;
};
int getV0(Face* head, int index)
{
   Face* f = head;
   while(f)
   {
      if(f->index == index)
         return f->i0;
      f = f->next;
   }
   return 0;
}
int getV1(Face* head, int index)
{
   Face* f = head;
   while(f)
   {
      if(f->index == index)
         return f->i1;
      f = f->next;
   }
   return 0;
}
int getV2(Face* head, int index)
{
   Face* f = head;
   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();
}

This topic is closed to new replies.

Advertisement