|
sshh dont advertise it now!
|
|
|
|
|
I'm sure your pull request wasn't rejected because your variable name was too short, it was rejected because the name is not descriptive.
Your new name, aNumber, is equally undescriptive so should be rejected again.
Let's say Value returns a wrong value and I had to fix it, I'd see a generic Calculation, an x and some flag.
This tells me absolutely nothing about what the code does or is supposed to do.
Heck, I don't even know what Value is, but perhaps that's clear from the class context (unless you named that C, which wouldn't surprise me now).
All in all, very hard to debug, I can't make assumptions about the code, I'd have to go all the way up or down the stack to know where Value or flag came from or is used, I'd have to read the entire Calculation function to find out what is being calculated... In short, I'd have to read the entire code base just to get a gist of what this little piece of code does and remember it all!
I'm with everyone else on this thread and on your team, apparently, your code is bad and you should feel bad.
|
|
|
|
|
|
I agree with you, I don't have a problem using x or i for throw away values like in the example you gave or in OriginalGriff's example. Anything longer can detract from the logic.
I found the comment under the Edit interesting because I have the same issue you have, I've always suspected that I'm slightly dyslexic (never investigated though).
// TODO: Insert something here Top ten reasons why I'm lazy
1.
|
|
|
|
|
Yeah, glad to know I am not alone!
Seeing all the strong opposite reaction, I am starting to believe, just as long variable names are a real impediment to my comprehension. Many might have a sort of opposite problem.
Though, and I am digressing here, from the strongly opinionated people I fear an even worst problem. Focus on names at the detriment of the logical operation...
|
|
|
|
|
Super Lloyd wrote: Seeing all the strong opposite reaction I think you are seeing a polarization that is not as intense as you may be experiencing it.
I see the gist of the comments here as focusing on code readability, maintainability ... in the context of a project with multiple programmers, and a code base where any accidental semantic clash, or mis-interpretation of the meaning of names, can have disastrous consequences, cause needless confusion, etc.
I am reminded of when I joined the Illustrator team at Adobe, and, out of curiosity, looked in the source for functions that converted whatever to hexadecimal: there were 17 different functions, most of which were duplicates ... that no one dared to change
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
modified 7-Sep-21 5:59am.
|
|
|
|
|
design by committee... the plight of any big corp! ^_^
|
|
|
|
|
The code bases of the existing Adobe products I worked on, PhotoShop, Illustrator, were the opposite of design by committee: they grew by accretion. New, "hot," features always took precedence over any systematic re-org.
By the way, I have complete respect for the world-class programmers I had the chance to work with, and, I felt continually humble in their presence ... for good reasons: I was a one-trick pony
When they did the PC version of PhotoShop, they found the Mac code (using the MacApp framework) impossible to port "native," so they re-implemented MacApp on Windows, which took a tremendous effort. [^]
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Variable names should be long enough to explain what they do but short enough to be succinct. Very long names show you haven't thoroughly worked out what they are for or you are being too restrictive.
For example, the other day I was writing some code that I hadn't thoroughly thought through and I created a variable called something like locationOfCommonSharedValuesBeforeTheConfigurationWasJoinedToAnotherEnvironmentsConfiguration . After much soul searching, it is now called originalSharedValues .
|
|
|
|
|
Super Lloyd wrote: For example a simple expression like a = b + c
can confuse me if you write instead myobjectBlu = aCycleValueOrdinal + meteorStrikeOffsetTime .
Good example.
Without greater context, I can't tell whether "b + c" is the correct thing to do to get "a".
Given your second example however, if I know that in order to get myobjectBlu, the equation needs meteorStrikeOffsetTime to be multiplied by a constant before being added to aCycleValueOrdinal, then I can spot this.
[Edit]
Just being devil's advocate. I have to imagine that someone reviewing this would see the greater context and not just look at the one line.
|
|
|
|
|
Super Lloyd wrote: double Value
{
get
{
var x = Calculation();
return flag ? x : 2 * x;
}
}
Here's my comment - do NOT use var! Using var instead of double forced me to look in a second place in your code to figure out what I was reading. var is an abomination.
|
|
|
|
|
obermd wrote: var is an abomination.
when used improperly.
Our shop uses var all the time.
var myClass = new MyMostExcellentClassInTheWholeWideWorld(); this is acceptable IMHO and the opinions of hundreds of thousands of developers world wide, if not millions, billions, and trillions.
var something1 = something2.GetSomething3(); this is not acceptable.
This is a hotly debated topic, I know. To each there own.
|
|
|
|
|
and now, C# 9 brings you "even more naked" instantiation:
List<int> xs = new();
List<int>? ys = new();
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
BillWoodruff wrote: List<int> xs = new();
List<int>? ys = new();
stuff like this is just retarded.
it is really for the people who hate "var". These people want to see the instantiation on the left, rather than the right.
It makes me laugh and cry all the way home.
modified 7-Sep-21 10:28am.
|
|
|
|
|
This works as well because it's obvious from the single line of code the type of the variable.
|
|
|
|
|
This example works because the class name is in the same line of code.
|
|
|
|
|
I agree, the length of a variable name should be proportional to its scope and visibility.
The reader should be able to see a one-letter variable and just know that it has only local scope. Any developer who gets confused by such a thing does not belong on my team.
The fewer the characters, the easier to read.
|
|
|
|
|
Thinking about my own code I realize I do this as well. Descriptive names for globals or widely used variables and functions and short names for local use only.
|
|
|
|
|
In 23 years, I've never had my code reviewed. I feel lucky!
"Go forth into the source" - Neal Morse
"Hope is contagious"
|
|
|
|
|
I use "i" in for loops. That's it.
Edit:
Also using "x and y" currently: for position coordinates.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I use descriptive names, which tend to be long.
Short names in my code depend upon context. Here's an example:
for (int JMi = 0; JMi < JettingModules.Length; JMi++)
{
JettingModules[JMi].DoStuff(...);
} I will occasionally use short names synonymously to long names in order to make a complex expression simpler to understand or read:
bool ready = StitchCalibration.Context.Ready(...);
bool online = Framework.Online && DFE.Service.Connected;
int retry = 0;
while (ready && online && (retry < 3))
{
} My names are chosen to tie related concepts together and for clarity of expression.
Software Zen: delete this;
|
|
|
|
|
"depends on context"
Amen !
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Greetings My code has never been reviewed but am curious if it were I might learn something or teach the reviewer a thing or two Wouldn't mind reviewing others' for the same reason- Cheerio
PS As for naming It seems obvious names should be as long as necessary to indicate intent when they set context Short is fine once context is set Also the name can indicate the type and value range of the identifier e.g. "calculateWidth_ofImpendingMeteorStroke" will never return a negative value Further have some sympathy for the poor chap who will maintain the code or for yourself many months or years hence Further I like to utilize different naming conventions to indicate the scope of the identifier I always utilize snake for local and now tend to camel for class and prefix with a 'g' for the rare global
"I once put instant coffee into the microwave and went back in time." - Steven Wright
"Shut up and calculate" - apparently N. David Mermin possibly Richard Feynman
|
|
|
|
|
If you use Git you are likely, but not necessarily, to have review.
(not using Git here thought)
At any rate, certainly, every now and then there is very good feedback in review.
However every single time it waste a lot of time.
|
|
|
|
|
Right, tell your maths lecturer to use long variable names, instead of x and y.
Nothing succeeds like a budgie without teeth.
|
|
|
|