Thread: Are namespaces a good idea?

  1. #1
    Newbie Crilston's Avatar
    Join Date
    Jun 2005
    Location
    Montreal, Canada
    Posts
    8

    Are namespaces a good idea?

    Are namespaces a good idea for game development? Like, if I do like this:
    Code:
    namespace Polarr
    {
        namespace Engine
        {
            extern class Color;
            extern class Vector;
        }
        namespace Network
        {
            extern class Server;
            extern class Client;
        }
    }

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Yes. Anything with more than one "section" should use namespaces.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Namespaces and whitespace are a good idea, they make the code clearer, and laot easier to amend and view. also, in the real world, just think of a program the size of final fantasy XII with out spacing... what a mess it would be!!!

  4. #4
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    swgh, maybe I'm wrong, but from your post it would apear that you do not know what a namespace is. It has nothing to do with spacing and formatting, it is like a class but you don't create an object for it. They would be important in a large game with many programmers, because if they each have a different namespace, they don't have to worry about giving variables the same name without knowing it.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I think namespaces are good, although, with classes and such most namespace clash issues have been resolved, even in larger projects.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Location
    Stockholm, Sweden
    Posts
    64
    I tend to use namespaces to create 'modules', if several classes are always/often used together I group them in a namespace. A quick example (not from a C++ project actually, I used Ruby) is a small app I wrote at work.

    It's used to manage the data we have stored about the assets in our company, so each asset is modeled within the class Asset, then I have an AssetCollection class to collect assets and also a Validator class to validate asset IDs (you wouldn't believe how mangled some of the input is ).

    Each of these are grouped in a module (Ruby's version of namespaces) called Asset, so Asset::Asset, Asset::AssetCollection and Asset::Validator.

    I find the best way to think about namespaces is to think of them as logical groupings of classes.

  7. #7
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361
    Quote Originally Posted by swgh
    Namespaces and whitespace are a good idea, they make the code clearer, and laot easier to amend and view. also, in the real world, just think of a program the size of final fantasy XII with out spacing... what a mess it would be!!!
    Quote Originally Posted by SirCrono6
    swgh, maybe I'm wrong, but from your post it would apear that you do not know what a namespace is. It has nothing to do with spacing and formatting, it is like a class but you don't create an object for it. They would be important in a large game with many programmers, because if they each have a different namespace, they don't have to worry about giving variables the same name without knowing it.
    Funny, I thought he was kidding .

    Eh I don't like namespaces. They ARE a good idea, but I think that it's more personal preference. I guess if you are on a large project...I really just don't like them, I guess it's my problem
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opinion on GOOD digicam
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-22-2003, 05:37 PM
  2. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 11:50 AM
  3. IDEA: Text Summarization
    By Perspective in forum Contests Board
    Replies: 2
    Last Post: 07-27-2003, 12:35 PM
  4. good or bad game idea you vote?
    By L_I_Programmer in forum Game Programming
    Replies: 3
    Last Post: 03-15-2003, 07:14 AM
  5. Good site to learn about Prog. language concept?
    By Extrovert in forum Tech Board
    Replies: 5
    Last Post: 03-13-2003, 02:46 AM