What are the downsides to using namespaces?

Hi there,

Newbie question!
I'm only at day 30 and until now almost all functions are prefixed with 'Game' or 'Win32' and types likewise. I've looked at Caseys latest commit and it seems that he stopped prefixing the Game code after a while.

What is the reason not to structure code into namespaces? Is it searchability? Or because it is trivial because you can just name a function whatever you want?
Dont you benefit from knowing about the context of a function and allowing them to use the same name if they want to?

Something like this?

Game::GetState();
Game::Entity::GetState();
Game::Sound::AudioSource::GetState();

Thanks!
Hi Berend.

Not an answer to your question. I'm just informing you I'll be deleting the duplicate thread. There's no value in having two threads with the exact same question, so at a guess I'm going to say you duplicated the thread by mistake.

- Jeroen.
Berend
Hi there,

Newbie question!
I'm only at day 30 and until now almost all functions are prefixed with 'Game' or 'Win32' and types likewise. I've looked at Caseys latest commit and it seems that he stopped prefixing the Game code after a while.

What is the reason not to structure code into namespaces? Is it searchability? Or because it is trivial because you can just name a function whatever you want?
Dont you benefit from knowing about the context of a function and allowing them to use the same name if they want to?

Something like this?

Game::GetState();
Game::Entity::GetState();
Game::Sound::AudioSource::GetState();

Thanks!


Do you need to be reminded you are building a game?

Namespaces are meant to avoid name collisions. Not to organize your code into a hierarchy. In C, code isn't organized into hierarchies, id ir organized into files.

Your examples hint that you are thinking in OOP, so I will direct you to the many fine examples on the site of why that is bad according to Casey.

Also, we are using function overloading, which means we know what a function is doing both by its name and the data it is working on.
Berend
What is the reason not to structure code into namespaces?

Because its longer to type.
Compare "Game::GetState" vs "GameGetState" or "GetGameState" - 14 vs 12 characters. Why complicate life and make everything longer to type and take more horizontal space on screen?

Edited by Mārtiņš Možeiko on
I see I see, very valid arguments.

I guess that I'm still thinking too much in terms of OOP and you're right about that Mārtiņš.

Thanks for you answers :)

@Jeroen Yes I thought that I posted it in the wrong thread ;) Thanks