Re: Comments solicited about stylistic preference
phdscholar80@yahoo.com wrote:
I have the habit of using the scope resolution operator whenever I use
global functions. My premise is that it improves readability by
helping someone who is looking at the code for the first time to grasp
at once that the function has global scope. I stretch this habit to
using the operator on C library functions as well. So I write ::memset
instead of memset and ::abs instead of abs.
According to the Standard, if you (and the implementors) do the right
thing (which is rare, BTW), you're not supposed to use the global names,
but instead use 'std::' prefix.
I vaguely remember
hearing/ reading somewhere that it is encouraged practice to use fully
qualified names of STL elements, e.g. std::vector instead of vector.
Can someone verify this?
It's really difficult for me to verify whether you remember hearing
or reading something somewhere, you understand this, don't you?
All constructive comments are welcome.
Well, not giving into the desire to reduce having to type too many
characters by inserting 'using namespace std' or a using declarations
with standard names, is a good habit. Of course, you're going to
eventually run into this situation:
std::deque<
SomeRatherLongTypeName,
OtherLongNameOfTheAllocator> myRatherLongTypeNameCollection;
and then you want to iterate of it using 'const_iterator'... How
bad is that? Then you resort to
typedef std::deque<
SomeRatherLongTypeName,
OtherLongNameOfTheAllocator> myTypeCollection_t;
and iteration becomes realtively easy then
myTypeCollection_t::const_iterator ...
Doing all that does *hide* the fact that the collection is, in fact,
a standard container. Well... I say, so? Bid deal!
Now, with some old (and even sometimes with some new) codebases there
can be a name conflict with some popular names like 'min' or 'max'.
You have to watch out for those. The bad thing is when somebody
actually switches those without you actually knowing it. There is
definitely less probability of a mistake if you fully qualify those.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask