Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. I heard this somewhere

I heard this somewhere

Scheduled Pinned Locked Moved The Lounge
c++question
19 Posts 10 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Yeah, Shortly after I responded to your post I remembered some other details. I can remember that std::mutex and boost::mutex were nearly identical so I could seamlessly switch the code below from boost to the std namespace simply by changing the using-namespace declaration. It's a bit frightening when you discover three days later that you forgot to change a mutex in a few places.

    //using namespace boost;
    //using namespace std;

    mutex m;
    m.lock();
    //... something here
    m.unlock();

    Can't make that mistake if you use the entire scope:

    std::mutex m;
    m.lock();
    //... something here
    m.unlock();

    N Offline
    N Offline
    Nelek
    wrote on last edited by
    #10

    Randor wrote:

    Can't make that mistake if you use the entire scope:

    care to elaborate?

    M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

    L 1 Reply Last reply
    0
    • N Nelek

      Randor wrote:

      Can't make that mistake if you use the entire scope:

      care to elaborate?

      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #11

      Nelek wrote:

      care to elaborate?

      We are discussing C++ namespaces[^]. C++ code containing using-declarations[^] can lead to scope resolution ambiguity. boost::mutex[^] std::mutex[^] I am sharing my opinion that using-declarations should be avoided. Best Wishes, -David Delaune

      N 1 Reply Last reply
      0
      • L Lost User

        Nelek wrote:

        care to elaborate?

        We are discussing C++ namespaces[^]. C++ code containing using-declarations[^] can lead to scope resolution ambiguity. boost::mutex[^] std::mutex[^] I am sharing my opinion that using-declarations should be avoided. Best Wishes, -David Delaune

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #12

        Yeah, I had understood so far. But I didn't get the sentence I quoted. I suppose that you meant using the "std::" or "boost::" as prefix, you have less probability of getting errors than unsing both "using", i.e. because some methods might have similar parameters but different behaviour.

        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

        1 Reply Last reply
        0
        • H honey the codewitch

          Personally, I think it's fine in your main.cpp Anywhere else, such as in a header, it clutters your global naming container. In general, don't use "using namespace" in headers at all. Some people here might suggest that using namespace std, even in main.cpp is bad form because of all the stuff it drags in. I suggest those people relax. :)

          Real programmers use butterflies

          D Offline
          D Offline
          den2k88
          wrote on last edited by
          #13

          honey the codewitch wrote:

          Some people here might suggest that using namespace std, even in main.cpp is bad form because of all the stuff it drags in.

          As if linkers are that stupid...

          GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

          H 1 Reply Last reply
          0
          • D den2k88

            honey the codewitch wrote:

            Some people here might suggest that using namespace std, even in main.cpp is bad form because of all the stuff it drags in.

            As if linkers are that stupid...

            GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #14

            Not that. Just that people don't like intellisense coming up with a billion and a half entries every time it opens.

            Real programmers use butterflies

            D 1 Reply Last reply
            0
            • H honey the codewitch

              Not that. Just that people don't like intellisense coming up with a billion and a half entries every time it opens.

              Real programmers use butterflies

              D Offline
              D Offline
              den2k88
              wrote on last edited by
              #15

              I use VisualAssistX, it usually gives good entries anyway.

              GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

              H 1 Reply Last reply
              0
              • D den2k88

                I use VisualAssistX, it usually gives good entries anyway.

                GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #16

                I just use VS Code with minimal frills when I do C++. It mostly stays out of my way and that's what I like about it. It has a few quirks, but so does everything.

                Real programmers use butterflies

                D 1 Reply Last reply
                0
                • H honey the codewitch

                  I just use VS Code with minimal frills when I do C++. It mostly stays out of my way and that's what I like about it. It has a few quirks, but so does everything.

                  Real programmers use butterflies

                  D Offline
                  D Offline
                  den2k88
                  wrote on last edited by
                  #17

                  I tried VSCode and while I find it all in all good I despise its side-panels management. When I can I cram everything in VS and use the external toolchain to compile. I'm using it for an embedded Linux sw, I used it for microcontrollers... :D

                  GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                  H 1 Reply Last reply
                  0
                  • D den2k88

                    I tried VSCode and while I find it all in all good I despise its side-panels management. When I can I cram everything in VS and use the external toolchain to compile. I'm using it for an embedded Linux sw, I used it for microcontrollers... :D

                    GCS d--(d-) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #18

                    They never bothered me that much. Once I got the hang of ctrl+click to open in the side it was all gravy for me. Mostly I like VS Code because it's got a nice mix of minimal UI wrapped around maximum functionality. I have yet to find a file type it can't open. Makes it super nice for me working on my TTF library because I can just open a test font file and look at all the glyphs in VS Code. I really hope they backport some of that functionality into Visual Studio or something but I doubt it because they are such different products.

                    Real programmers use butterflies

                    1 Reply Last reply
                    0
                    • Richard Andrew x64R Richard Andrew x64

                      (This post is being submitted under the protection afforded by Lounge posting rule #2.) I read somewhere on this site that someone had written that it's bad practice to use "using namespace std;" in your C++ code. Can anyone explain the theory behind this?

                      The difficult we do right away... ...the impossible takes slightly longer.

                      K Offline
                      K Offline
                      KateAshman
                      wrote on last edited by
                      #19

                      A.k.a. namespace pollution. If you import a large amount of classes/functions, that you do not know the name of, you end up with a higher risk of running into namespace collisions.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups