@
jgg2002
I know all about the variable names. But, I didn't really need to name them grade1, grade2, grade3... g1 works just as well. |
I still disagree. The trouble with short variable names everywhere, is that the code becomes cryptic. Plenty of times before, people have looked at
their own code from a few months prior say, and haven't understood it.
Also, you may not be the only one looking at the code: In industry you would probably get a talking to, if you wrote code like that at work. And this is one of the reasons why Coding Style Guides exist: they try to sort out problems that come from bad style, by promoting good style to start with.
IMO, the perception that one
needs to abbreviate everything becomes a disease. Maybe it started with C programming, wasn't helped at all with Hungarian Notation, then was sorted out more and more with larger projects. People realised that they had to have better style to avoid problems. With C, it might not have been such a problem, one is supposed to have have short functions everywhere (but this doesn't always happen). C++ is supposed to have short functions too, but there is often hell to pay if member variables, functions and objects have short meaningless names.
which requires more typing |
I wouldn't worry about abbreviating to avoid errors, the compiler will find most of the errors hopefully. And I think one is
less likely to mess up with a meaningful name.
Good variable and function names aid understanding and can help reduce problems. If one does it well, the code should read like a story. Here is a somewhat comical example of what I mean:
I am not saying short variable names are all bad, here is the guideline written by Bjarne Stroustrup and Herb Sutter, Section E7 is the one you want:
There is heaps of really good stuff in that document, it's worthwhile reading the whole thing.
IMO, an exception to short names is when the documentation (from wiki say) has mathematical equations. It's sensible to stick with the conventions in the documentation. I would comment a link to it, and comment pasted individual equations as well. Most people who know any math would understand
y = r * sin(theta);
But some might argue for :
double YOrdinate = Radius * sin(ThetaAsRadian);
These could be named after what they actually are:
double RoofHeight = RoofSlopeDistance * sin(RoofAngleAsRadian);
This is much better than having
ra
, a classic mistake is to call
sin(ra)
when
ra
is in degrees, not radians.
Sorry if all this comes across as a lecture, but it could be quite useful to lots of other people too.
Regards :+)