Which way is better ?

This is a discussion on Which way is better ? within the C++ Programming forums, part of the General Programming Boards category; That is fine. I am merely pointing out that you shouldn't blindly put using namespace statements for every namespace you ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    That is fine. I am merely pointing out that you shouldn't blindly put using namespace statements for every namespace you encounter.
    Especially phantomotap seemed to think that explicitly specifying namespaces was like the old C days when you had to spell it all out. Or at least it seemed that way.
    I didn't agree, because I use namespaces for categorizing. And the using isn't evil; there are places where it helps, like in your example, and others where it does not.
    Myself, if it is not too long, I do prefer to type it out explicitly.
    Last edited by Elysia; 02-10-2009 at 09:47 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,231
    I'm just saying one [...] not back in the C era.
    O_o

    You are confusing "may" with "must".

    If one "may" fully qualify names, for whatever reason, it isn't bad at all.

    If one "must" fully qualify names, the namespaces are being used solely as a prefix. All the advantages of namespaces are lost. There is no difference between one prefix notation and the other. The source may only use ':' instead of '_'.

    Which is more readable?

    Code:
    std__copy(std__istream_iterator<std__string>(std__cin), std__istream_iterator<std__string>(), std__ostream_iterator<std__string>(std__cout, " "));
    Code:
    // using directives
    copy(istream_iterator<string>(cin), istream_iterator<string>(), ostream_iterator<string>(cout, " "));
    Soma
    Last edited by phantomotap; 02-10-2009 at 09:59 AM.

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,636
    Quote Originally Posted by whiteflags
    Namespaces are there to resolve things when the same identifier has been used multiple times, and the above communicates to me that namespaces somehow lose their value when they fulfill their purpose.
    I think you have made a strawman argument since phantomotap compared namespaces to name prefixes, and it is in that context that he stated that "all the advantages of namespaces are lost" (emphasis mine).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    *shrug* I deleted my comment because it occurred to me that Soma was probably saying what I was saying, in so many words. That happens. I'd ignore him so that I don't bug him but he's actually smart, says great advice, and that's mean.

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Quote Originally Posted by phantomotap View Post
    O_o

    You are confusing "may" with "must".

    If one "may" fully qualify names, for whatever reason, it isn't bad at all.

    If one "must" fully qualify names, the namespaces are being used solely as a prefix. All the advantages of namespaces are lost. There is no difference between one prefix notation and the other. The source may only use ':' instead of '_'.

    Which is more readable?

    Code:
    std__copy(std__istream_iterator<std__string>(std__cin), std__istream_iterator<std__string>(), std__ostream_iterator<std__string>(std__cout, " "));
    Code:
    // using directives
    copy(istream_iterator<string>(cin), istream_iterator<string>(), ostream_iterator<string>(cout, " "));
    Soma
    Ah, yes. You are right. Still, I prefer
    Code:
    std::copy(std::istream_iterator<std::string>(std::cin), std::istream_iterator<std::string>(), std::ostream_iterator<std::string>(std::cout, " "));
    Not only do they avoid collisions (which is pretty irrelevant in this example, but still), but I can see where they come from, and I do like to prefix this explicitly, unless too long.
    Now, those are good arguments to ponder. When to use using namespace directories and when not to?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,231
    I'd ignore him so that I don't bug
    ^_^

    You shouldn't bother about that; everyone bugs me anyway.

    When to use using namespace directories and when not to?
    Beyond rules that prevent pollution or allow overload resolution, this seems to fall under the realm of style.

    Soma

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21