This topic is 1533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

The right balance depends on the scope of the variable. If you've got a 3-line loop body, with Vec3 p = blah.position; as the first line, then there's no problem, as further explanation about what 'p' means appears in the same context.
If someone has a member variable named 'p', then the class better be pretty damn simple/small/self-explanatory.
If someone has a global variable named 'p', they can GTFO ;-)

The larger the scope, the longer the appropriate name length.

Yeah, that sounds like a reasonable line of reasoning.

##### Share on other sites

The right balance depends on the scope of the variable. If you've got a 3-line loop body, with Vec3 p = blah.position; as the first line, then there's no problem, as further explanation about what 'p' means appears in the same context.
If someone has a member variable named 'p', then the class better be pretty damn simple/small/self-explanatory.
If someone has a global variable named 'p', they can GTFO ;-)

The larger the scope, the longer the appropriate name length.

Yeah, that sounds like a reasonable line of reasoning.

I think it's reasonably reasonable for you to say that his reasoning is reasonable.

##### Share on other sites

The right balance depends on the scope of the variable. If you've got a 3-line loop body, with Vec3 p = blah.position; as the first line, then there's no problem, as further explanation about what 'p' means appears in the same context.
If someone has a member variable named 'p', then the class better be pretty damn simple/small/self-explanatory.
If someone has a global variable named 'p', they can GTFO ;-)

The larger the scope, the longer the appropriate name length.

Yeah, that sounds like a reasonable line of reasoning.

I think it's reasonably reasonable for you to say that his reasoning is reasonable.

How reasonable of you!

##### Share on other sites

The reasonable amount of reasonably reasonable posts in this reasonable thread is reasonably reasonable.

...I dare you to read that sped up =P

##### Share on other sites

I think that everyone is being too reasona...oh what the crap, it isn't worth it.  I'm screwing it up.  This being reasonable stuff is becoming unreasonable!

##### Share on other sites

I came to provide some reason to this thread, but I see it has enough already.

Note: There is some serious physics simulation software (see GADGET-2) that has some horribly named variables. It's very readable to a physicist, but makes a CS major bawl. Different area, different rules.

To state the obvious: There just isn't a 'global' set of rules on how we should name variables, even something like 'readability' and understandability differs from group to group. Physics equations fall apart when you start naming things "velocity_x" and then using it all over the place and being able to find an error in the code gets worse the less it looks like an equation and the more like code it looks. Tracking down these kinds of errors is a bitch.

But as someone reasonably stated: The wider the scope, the longer the name should be. Or, fuck, leave a comment that says "Look up the equation in such and such's paper, or book on page x"

##### Share on other sites

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.

That is clear and concise compared to alot/much of code Ive worked on in my professional career

Add some blanks spacings and carriage returns and some alignment/indentation  of common statement elements and tnat would be clearer than most of the Microsoft code Ive seen

Ive seen alot of code in 'books' that are the opposite spaced out rediculously

Just do what I do and take a library like that and put it through a 'pretty' printer program I wrote that reorgamizes the code to my own style (or do it by hand - seriously it wont take that long and you would get a readthrough of the code giving you some understanding of what the lib actually does)

---

as for variable names most of those usages are very tight minimal in their function  (let hear after you start having 8 way nested loops)

Now if they start having object class  with dozens of attributes or more obscure usage of the variables (besides initialization loops)  then longer names are warranted.

Edited by wodinoneeye

##### Share on other sites

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

Yea I know what you mean. I usually just write out the full name for my variables, with comments on what each of them are meant to be used for. Takes longer to type but helps me out in the end when coming back to my code to get myself up to speed.

##### Share on other sites
int      l, dijk, dijkl, dijkr, ima, qi, qj, qidiv, qjdiv, fi, fj, fijk2;
double   disx, disy, switchx, switchy, switchx2 ,disxl, disxr, disx2, disxr2;

dijk    = di + nx * (dj + oy * dk);
ima     = step_div(dk - ez, nz);
qj      = dj + step_int(-ima * byz * ysp);
qjdiv   = step_div(qj - ey, ny);
qi      = di + step_int((-ima * bxz - qjdiv * bxy) * xsp);
qidiv   = step_div(qi, nx);
fi      = qi - qidiv * nx;
fj      = qj - qjdiv * ny,

fijk    = fi + nx * (fj + oy * (dk - ima * nz));

disy    = ima * byz + qjdiv * by;
switchy = (dj - ey) * boxy - ima * byz - qjdiv * by;

disx    = ima * bxz + qjdiv * bxy + qidiv * bx;
switchx = di * boxx - ima * bxz - qjdiv * bxy - qidiv * bx;

//This is what you would largely see after my usual treatment
//(and I likely would add some extra parens around the multiplies
//to emphasise the ordering

Does look a bit clearer after youve isolated the variable definitions (that partial list) from the calculation statements and added spacers to make the functions and variables more distinct.

Imagine how much more fun the above code would be with ALL  8+ char variable names  (and those function name would have to be expanded too --- wouldnt they ?....)

Short variable names dont bother me so much - but if there is anything weird/unusual  being done I will heavily comment to make clear some atypical code.

Edited by wodinoneeye

##### Share on other sites

Looks to me like an implementation of some paper. If you want your code to be easily understandable for someone who knows the paper, I guess this is not that bad style. One might want to add an underscore to express subscripts in TeX-style like in "d_ijk". Sure, you don't easily understand the code without knowing the source of the algorithm, but if you name your stuff to match names from the paper you're implementing, people will find it easier to verify your implementation against the paper...

If this code was written without a scientific paper as its background, well... that'd be bad ;-)

##### 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;


WTF?!

I have never seen something so bad in my life when it came to horrid variable names and completely unreadable code. Seriously.

##### 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;

WTF?!

I have never seen something so bad in my life when it came to horrid variable names and completely unreadable code. Seriously.

Theirs the thread that spawned the great gd.net horror experiment, suggest you check it out if you wanna see something truly horrible.