Like Tree5Likes
  • 1 Post By whiteflags
  • 4 Post By Cat

Benefit of Namespaces

This is a discussion on Benefit of Namespaces within the C++ Programming forums, part of the General Programming Boards category; I cant seem to see the immediate benefit of namespaces. At first sight, the only benefit is ofcoarse using the ...

  1. #1
    Registered User Vespasian's Avatar
    Join Date
    Aug 2011
    Posts
    181

    Benefit of Namespaces

    I cant seem to see the immediate benefit of namespaces. At first sight, the only benefit is ofcoarse using the same global variable names throughout a project through the use of preceding those variable names with their respective namespaces. But why is this a benefit when in the first place these variables can be named differently to avoid causing re-definition?

    What are the real benefits to namespaces that I cant seem to pick up?

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,622
    I cant seem to see the immediate benefit of namespaces. At first sight, the only benefit is ofcoarse using the same global variable names throughout a project through the use of preceding those variable names with their respective namespaces. But why is this a benefit when in the first place these variables can be named differently to avoid causing re-definition?
    We mere mortals tend to be uncreative in this area. Boost wants to differentiate their libraries from standard ones, but that doesn't mean they have to come up with a new name just because the standard laid claim to a generic name like "array". When you are first learning it is hard to see how namespaces really do anything because you are constantly using only the std namespace.

    What are the real benefits to namespaces that I cant seem to pick up?
    Naming a namespace after yourself.
    laserlight likes this.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,478
    Makes it easier to use or write third party Libraries.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Quote Originally Posted by Vespasian View Post
    I cant seem to see the immediate benefit of namespaces. At first sight, the only benefit is ofcoarse using the same global variable names throughout a project through the use of preceding those variable names with their respective namespaces. But why is this a benefit when in the first place these variables can be named differently to avoid causing re-definition?

    What are the real benefits to namespaces that I cant seem to pick up?
    On any project of significant size, the likelihood of name collisions is very high. It's also a way to organize and collect code at a level higher than the class.

    Why do you have folders on your computer instead of just putting everything directly into C:\ ? The same reasons you collect files together into a directory are why you might collect classes into a namespace.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    What happens if library X and Y both have the class/function Z, and you need to use both? Unless you are using namespaces, it just won't work! The names would collide. But namespaces would avoid that...
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to preserve the benefit of fgets?
    By ulti-killer in forum C Programming
    Replies: 14
    Last Post: 07-12-2012, 05:42 AM
  2. Charity Race to Benefit Medical Research May 15 - 25th
    By Adak in forum General Discussions
    Replies: 1
    Last Post: 05-27-2012, 04:42 AM
  3. Namespaces
    By tim545666 in forum C++ Programming
    Replies: 3
    Last Post: 05-04-2002, 12:36 AM
  4. what is benefit of using window NT?
    By Mane in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 03-29-2002, 07:13 AM
  5. For the Benefit of Mr. Kite
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-25-2001, 06:24 AM

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