SFML community forums

General => SFML website => Topic started by: Kyle on September 29, 2009, 06:34:08 pm

Title: Why do you put sf:: in tutorials
Post by: Kyle on September 29, 2009, 06:34:08 pm
Why is it in functions sf:: is getting used, doesn't using namespace sf; eliminate the need for this?
Title: Why do you put sf:: in tutorials
Post by: Laurent on September 29, 2009, 06:56:43 pm
Quote
doesn't using namespace sf; eliminate the need for this?

I have a better idea. Not using a namespace at all in SFML eliminates the need for "using namespace sf".

Seriously, I leave the choice to the user. And I can't put "using namespace sf" in every piece of code of the tutorials. So at least by prefixing every class with sf:: I'me sure that I won't get hundreds of stupid posts such as "the compiler doesn't recognizes my class??!!!!" on the forum ;)

PS: I personnally never use "using namespace xxx", and I think that you shouldn't consider it obvious to do so
Title: Why do you put sf:: in tutorials
Post by: phear- on September 29, 2009, 08:54:25 pm
Whats the point of namespaces if you use the "using namespace" command? There is no point that I can think of.
Title: Why do you put sf:: in tutorials
Post by: Nexus on September 29, 2009, 08:58:30 pm
Quote from: "Laurent"
PS: I personnally never use "using namespace xxx", and I think that you shouldn't consider it obvious to do so
Me neither (except for some really rare cases inside a local function, for example to access an enum which is surrounded by a namespace). And I don't think avoiding this is bad practice. Most important, never write the using directive into headers because the whole namespace is emptied out in all including files.

One can also contribute reducing the global namespace pollution by not using using namespace :D
Title: Why do you put sf:: in tutorials
Post by: Nothingness0x on December 11, 2009, 09:38:11 am
I find it better to use "sf::" that gives personnality to SFML, besides I'm not for namespace at all, because you can do mistake if there's a same name in two differents librairies, for exemple sf::String and std::string. I personnaly use the namespace only for STD, and using "sf::" allow you to directly recognize that you are using a SFML function.  :D
Title: Why do you put sf:: in tutorials
Post by: Laurent on December 11, 2009, 09:45:17 am
Quote
besides I'm not for namespace at all, because you can do mistake if there's a same name in two differents librairies, for exemple sf::String and std::string

That's exactly what namespaces are for ;)
Title: Why do you put sf:: in tutorials
Post by: Nothingness0x on December 11, 2009, 10:03:25 am
Sorry i was meaning that I'm not for writting "using namespace ..."  , just a misunderstanding  :)