either way, I would like C++0x to come with some refactored code, sick of seeing scALs::SP_XXX etc.
either way, I would like C++0x to come with some refactored code, sick of seeing scALs::SP_XXX etc.
What do you mean?Originally Posted by indigo0086
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I tend to prefer knowing whether a variable is a class, structure, pointer, string, float or a banana. So sz, lp, dw, w, b, byte, f etc are very helpful.
"The Internet treats censorship as damage and routes around it." - John Gilmore
lp is kind of useless, since every pointer these days is a long pointer, so just p should suffice.
As for the others, they depend on the actual data type, which might change (char* to std::string for example) and then you'd have to rename all the szVar names to strVar...
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
What about changing a signed integer to unsigned or the other way round?
What about polymorphism? How do you indicate what type the pointer points to?
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Non sequitur. As has been mentioned in this thread several times, you can know the type of the variable without encoding it into the name, especially if you declare the variable near first use, and write functions that do one thing and do it well. Granted, the difference between a class and a struct will not be evident, but it is unnecessary information anyway since the language level difference is superficial, while the semantic difference (e.g., the convention of structs being used to define aggregates) can be conveyed by a descriptive name.Originally Posted by maxorator
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I agree with laserlight. I've been reading a book on Clean Code by bob martin and it highlights some of that. I've never had the need for encoded variable names when the names are descriptive and are near it's use. Anything else screams global variable and we know how that is. Even when I'm doing javascript stuff I try to keep these methodologies, and they only have var and function to work with.
And what I meant laserlight is the variable names, type names, and defines in the standard C/C++ library that I think pollute most of their intent. It also doesn't fare well with code intelligence helpers.
Last edited by indigo0086; 05-12-2009 at 02:19 PM.
You people always fight against that statement ("I just know what this variable is, it doesn't need to be descriptive.") because it's the excuse for writing bad code. I don't see that anything is different here.
If the pointer can point to different types then it is a pointer to void, so you just indicate it with a p.
Last edited by maxorator; 05-13-2009 at 06:32 AM.
"The Internet treats censorship as damage and routes around it." - John Gilmore
"The Internet treats censorship as damage and routes around it." - John Gilmore
There is an important difference here: a type encoding (i.e., Systems Hungarian) is not as descriptive as the type itself, and is not guaranteed to be in sync with the type. If you were arguing for a semantic encoding (i.e., Apps Hungarian), then indeed there would not be anything different from a normal descriptive name other than the need for a programmer new to the code base to learn the commonly used abbreviations.Originally Posted by maxorator
It sounds like you consider class and structures to be some kind of supertypes by themselves. They are not. They are language constructs used to define types.Originally Posted by maxorator
EDIT:
But you stated that you "prefer knowing whether a variable is (...) a banana". How would you know if the variable was of the banana type if you do not abbreviate user defined types? Why should the built-in types and string types be treated as special cases, if (Systems) Hungarian notation is really so useful?Originally Posted by maxorator
Last edited by laserlight; 05-13-2009 at 10:23 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
By having the banana somewhere in the variable's name, but not as an abbreviated prefix.
Because the built-in types are the building blocks of everything else? There is a big difference between one data block (built-in types) and a collection of data blocks (structures, classes), therefore they should also be treated differently.
"The Internet treats censorship as damage and routes around it." - John Gilmore
The problem is that the difference does not warrant that they should be treated differently where type encoding is concerned. You could argue that perhaps, if it made sense to use type encoding in the first place, such abbreviation would be of most utility for types that are used most frequently. This would then imply that it makes sense to abbreviate the names of the built-in types, but it would also make sense to abbreviate the names of user defined types that are used frequently.Originally Posted by maxorator
However, the point remains: it does not make sense to use type encoding in the first place when the type system already exists such that convention is superfluous. With respect to C++, Stroustrup even goes as far as to regard (Systems) Hungarian notation as "completely unsuitable for a language that supports generic programming and object-oriented programming".
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
How come is it superfluous? If I read code written using Systems Hungarian notation, I see the data types of variables in the code. However, sometimes when I've tried to read some code written in "this_is_a_variable" style, I have to search the files for the declaration so I could know what type it is. Then when I see a next variable I do the same thing all over again. Imagine you have a variable "movie_rating" and you see the code for the first time. How do you know whether it is a byte, word, doubleword, float, double or a pointer to some structure or class containing more specific information?
"The Internet treats censorship as damage and routes around it." - John Gilmore