|
And if you change the DWORD to a WORD, do you diligently search and replace all references to the variable name with the corrected name? Maybe you do, but I bet a lot of other people don't. Plus, why code the storage method as part of the name? Isn't this why we have getter/setter methods, so we don't need to concern ourselves with internal implementation, and therefore don't care about the storage mechanism?
Marc
|
|
|
|
|
I'm happy with my notation
Pavel Sokolov,
CEZEO software,
LanTalk Network,
http://www.cezeo.com
http://www.lantalk.net
|
|
|
|
|
Marc Clifton wrote:
And if you change the DWORD to a WORD, do you diligently search and replace all references to the variable name with the corrected name? Maybe you do, but I bet a lot of other people don't.
Actually, I do that, and have no problem with it. If I'm changing the size of something, it's not a bad idea to go look at all usages of it as part of the change; it usually only takes a few minutes. Might as well change them whild looking.
Marc Clifton wrote:
Isn't this why we have getter/setter methods, so we don't need to concern ourselves with internal implementation, and therefore don't care about the storage mechanism?
As nice as that sounds, frequently we do care about the storage mechanism. For example, in communicating with external devices - whether they be musical instruments as in my work, or files, whatever - the size of storage is frequently hard-coded and must be respected. Sometimes data must be passed through a pipe of fixed size.. in which case data may be truncated and precision or sign lost.
Here's another example: I work in a typical mixed environment, with character strings represent in various APIs as either char*, CString, or STL string. Frequently I have to deal with two or even all three types in the same chunk of code, all referring to the same text. In this case specific prefixes are very helpful.
|
|
|
|
|
In Pavel's defense, I too prepend variable names with their type. I find it generally helps the readability of the code. And yes - if I change a variable type, I do change the variable name accordingly - otherwise doing it in the first place is useless!!
You talk about having get/set functions for data hiding, but what about within the class itself?
I think after using it for a while you can really benefit. My colleague recently named some variables sBlah (CString) instead of saBlah (CStringArray) and it caused no end of confusion!
-Paul
|
|
|
|
|
PaulMdx wrote:
You talk about having get/set functions for data hiding, but what about within the class itself?
I use a strongly C++, object oriented notation with a data hiding and others cool stuff, inside the class too.
Pavel Sokolov,
CEZEO software,
LanTalk Network,
http://www.cezeo.com
http://www.lantalk.net
|
|
|
|
|
|
Marc Clifton wrote:
And if you change the DWORD to a WORD, do you diligently search and replace all references to the variable name with the corrected name? Maybe you do, but I bet a lot of other people don't.
Yes you should. And it is easy to do. Simply change the declaration and the compiler will not compile until you have made all the neccessary changes. This is about as close to forced self documenting code as it gets. Comments in context are far less easier to find and change.
Marc Clifton wrote:
Plus, why code the storage method as part of the name?
OK, so you see the following line of code, what does it mean?
bone = currentBone;
Is bone a string or a number or a class? So now you have to look at it's declaration. OK, so now you say, "Well, I wouldn't have named it bone or currentBone."(Hey, neither would I.)"I would have named it boneIndex or boneName." OK, so is boneIndex an iterator or a number or a key in map template? As for boneName, is it const char * or string? All this information is very important in debugging.
Marc Clifton wrote:
Isn't this why we have getter/setter methods, so we don't need to concern ourselves with internal implementation, and therefore don't care about the storage mechanism?
This helps for setting/getting members of a class, but what if you are just dealing with variables within code.
Also, remember cast conversion operators are inheirent in even basic types so...
const char * currentBone = "leg";
int bone = 0;
bone = currentBone;
This compiles, but it would far less likely to be written if it was:
const char * pszCurrentBone = "leg";
int nBone = 0;
nBone = pszCurrentBone;
Jason King
|
|
|
|
|
Pavel Sokolov wrote:
Bad example
WNDENUMPROC
Good example
LPTHREAD_START_ROUTINE
Yep - I'm with you Pavel. The more verbose a name the better.
cheers,
Chris Maunder
|
|
|
|
|
I agree.
Edward_Francis_Gadziemski
|
|
|
|
|
I also make every effort to make my code as neat as possible. But at the end of the development cycle I always end up wondering who the heck wrote that pile of crap while I wasn't looking. I think that there is some kind of thermodynamic principle governing how this happens. It certainly isn't my fault!
I'm not a real reverend, I just play one on CP.
|
|
|
|
|
You are quite right
I have learned in my software engineering lectures, that there is some "rising entropy" in every software project. Big and long-living projects' code size increases about 10-20% per year - just because of maintaince entropy.
Themoynamics can explain us the whole world
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Reverend Stan wrote:
I always end up wondering who the heck wrote that pile of crap while I wasn't looking.
You too? Man - whoever it is sure gets around.
cheers,
Chris Maunder
|
|
|
|
|
Yeah, I feel physically sick when I look at my old code also.
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
You are the intrepid one, always willing to leap into the fray! A serious character flaw, I might add, but entertaining.
Said by Roger Wright about me.
|
|
|
|
|
Reverend Stan wrote:
I also make every effort to make my code as neat as possible. But at the end of the development cycle I always end up wondering who the heck wrote that pile of crap while I wasn't looking
You should have seen me agonising over every line before I submitted that CP+ thing. While I was writing it I was thinking "this rocks", but once it was ready to be submitted I checked over my code and though "god, they are going to have a good laugh at this."
And I kept looking for the Format Code button for C++ in VS.NET. No such luck... lol.
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
|
|
|
|
|
Paul Watson wrote:
And I kept looking for the Format Code button for C++ in VS.NET. No such luck... lol.
Are you sure? Boy, they really screwed the IDE then...
|
|
|
|
|
I can't see how anybody would go for an option other than this. All code must go through a development/debug/maintenance cycle.
So go for anything else would be professional suicide, but thats just my opinion.
Sure, depending on peformance you *may* have to compromise*, but with the speed of todays and future computers, this should be less of an issue as time goes by.
* I have never yet had to compromise, and I write real time apps for instrument control.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Roger Allen wrote:
Sure, depending on peformance you *may* have to compromise*, but with the speed of todays and future computers, this should be less of an issue as time goes by.
I have never seen a situation that has suffered reduced performance due to formatting concerns. And, I honestly believe that anyone who greatly reduces the performance of code (note that certain temporaries are usually optimized out) by doing formatting changes likely is someone that is not qualified to make those changes!
Peace!
-=- James.
"There is nothing worse than being oblivious to the fact that you do not know what you are doing."
[Get Check Favorites 1.4 Now!]
|
|
|
|
|
If there are different people involved in one project it seems to me that much better to have the code well-formatted and use Hungarian notation than headache translating it to understand, imagine everyone in the street began to drive just the way he likes
#define __ARMEN_H__
|
|
|
|
|
I agree with the formatting (but NOT with the Hungarian Notation idea!!! ). However, I've seen this go way over the edge, too, with "style guides" that mandate a particular number of spaces to indent, that all constants (even 0 and 1) must be #define 'd (even when 0 and 1 would make more sense), or other things so piddly and against the development environment that it becomes more work to maintain the formatting vs. maintaining the code.
(Regarding my anti-Hungarian Notation thing, in my 20+ years of experience, I've rarely needed to know at a particular spot what type a variable is supposed to be, but I've often needed to know what the purpose for a variable is. Sorry, but lpszText doesn't tell me beans. What's the text supposed to contain? Besides, it can be a maintenance nightmare when you discover that you need to change the datatype for whatever reason (e.g., it comes from an external source, and it changes from an int to a float ).)
|
|
|
|
|
But lpszAppPath tells.
#define __ARMEN_H__
|
|
|
|
|
So does appPath , and you don't have to worry about changing it from char* to CString .
|
|
|
|
|
The name lpszAppPath makes clear its type and what methods to use without going to its definition. And how often do you change char* to CString ?
#define __ARMEN_H__
|
|
|
|
|
Armen Hakobyan wrote:
The name lpszAppPath makes clear its type and what methods to use without going to its definition.
IMHO, I'd rather go back to the definition (and be sure somebody didn't change the type without changing the name!) than to wade through the garbage just to find the purpose of the identifier.
Armen Hakobyan wrote:
And how often do you change char* to CString ?
During prototyping, more often than one might think.
|
|
|
|
|
Ok ok.
#define __ARMEN_H__
|
|
|
|
|
appPath doesn't say nothing to me except that this is a path and suppose to be some sort of string, thought it doesn't have. We, for example, have paths defined in Database, so the path can be actually a long variable - ID in DB. See? Now I saw appPath and have NO idea what you mean by that, I have to go and search where it was defined, and if you hate HN, you won't use "m_" declaration for class members also, so your variable can be define anywhere. This increases programming time of your product for example.
BUT if you had declared your variable lpszAppPath , I can be sure that this is a string (LPCTSTR ), or if you declared nAppPath (in our particular case) I know that this is an ID to path in Database.
Simple as is
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
|
|
|
|
|