Earlier quoted context omitted.
The moral of the story is not to use shorter names, but to write better code. The scope of the post was variable naming. I used dates and "The Three Bears" for a light example of variable naming that almost anyone could understand. I did not even begin to address "better code". I'll save that for another (or hundreds of other) posts. Your Mama Bear example is some seriously broken date iteration code (so you change l…
My point is that naming verbosity depends on the code. This is vague but better than saying "cf. Goldilocks" ("choose anything between two crazy extremes"). My other point is that everyday use of names should be a guide for naming in code. The reason Mama Bear is wrong is that she's too formal. She gives a full explanation of the variable each time, but the 'full explanation' is the responsibility of the var setters,…
CodeThatDocumentsItselfSoWellItDoesNotNeedComments
31–40 of 40 posts
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#32Well, you can tell the developer of that was Indian.
I actually wasn't trying to be derogatory. "Do the Same" is a pretty common Indian English phrase. Just like "Do the Needful".
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#33I would rather support that, than most of the code I've actually been asked to support.
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#34Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#35There's a lot of "short vs long" going on in the comments here. That seems silly to me. Code should be written so as to completely describe the program's functionality to human readers, and only incidentally to be interpreted by computers. We have a hard time remembering short names for a long time, and we have a hard time looking at long names over and over again in a row. Additionally, short names carry a higher li…
What an awesome way to think about this. Thank you.
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#36I would rather support that, than most of the code I've actually been asked to support.
I bet the real code had all the other problems of real code PLUS the absurdly long names.... At that rate, I'd worry about carpal tunnel syndrome.
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#37I would rather support that, than most of the code I've actually been asked to support.
Is it really all that difficult to throw in a comment explaining what it is you're trying to do when it's not obvious to someone other than yourself?
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#38There's a lot of "short vs long" going on in the comments here. That seems silly to me. Code should be written so as to completely describe the program's functionality to human readers, and only incidentally to be interpreted by computers. We have a hard time remembering short names for a long time, and we have a hard time looking at long names over and over again in a row. Additionally, short names carry a higher li…
Unfortunately that would be a kind of kitchen sink feature that no standards committee is likely to accept. As a substitute, one could create a variable with a long name, then put the value into another variable with a short name, but that could be confusing unless very clearly noted in a comment.
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#39There's a lot of "short vs long" going on in the comments here. That seems silly to me. Code should be written so as to completely describe the program's functionality to human readers, and only incidentally to be interpreted by computers. We have a hard time remembering short names for a long time, and we have a hard time looking at long names over and over again in a row. Additionally, short names carry a higher li…
Long-uppercased names for anything global, settings or security-related (ie COOKIE_NAME, SECRET_HASH)
For dummy loop variables: i, j, k
For everything else I use common sense.
Re: CodeThatDocumentsItselfSoWellItDoesNotNeedComments
#40There's a lot of "short vs long" going on in the comments here. That seems silly to me. Code should be written so as to completely describe the program's functionality to human readers, and only incidentally to be interpreted by computers. We have a hard time remembering short names for a long time, and we have a hard time looking at long names over and over again in a row. Additionally, short names carry a higher li…