SFML community forums
General => General discussions => Topic started by: mweb on August 14, 2007, 11:14:43 pm
-
Why did you choose to use prefixes in front of each class instead of using a namespace for the how SFML? I usualy prefer to use namespaces but maybe you got a good reason for it.
-
Not really a good reason, it's more a personal style. Anyway, I don't think this is a problem, right ?
-
As namespaces are mainly used to avoid name conflicts, and as SFML classes are prefixed by "sf", I don't think that putting SFML in a namespace would be that useful ;)
-
I think he suggested to use sf::Window instead of sfWindow (for example), not sf::sfWindow ;)
-
Indeed. I think too.
It's not really useful for the moment :)
-
Ok it is not necessary but the namespace was added to the c++ that the prefixes for classes are no more necessary. But since this is your project it is your decision. And as you said it is not that important. I just wanted to ask.
-
Maybe one day it will be necessary. We'll see :)
-
I don't see a reason why it should get necessary, it is just more convenient and usually it is easier to change something if it is smaller and not bigger ;-)
We will see.
-
I agree with mweb. Namespaces had been created especially for this kind of consideration.
Indeed do not using namespace won't kill every babies seals of the world, but why do not use something especially created for that ?
I think mweb is right, it won't be necessary : that's just C++ philosophy, a C++ concept. A way to respect the reason.
Well, ok, I know that's not really important :)
-
hi, new user there im gonna give sfml a try :D
personally i like namespaces more also :P
have a nice day
-
I like them too.
It represents well modules and prevent name conflicts.
But putting SFML in a namespace is not urgent ;)
-
But putting SFML in a namespace is not urgent ;)
If putting SFML in a namespace is planned - then you should do it as soon as possible. Because if you will do it later (when there's nothing else to code) - you will create a lot of problems for the users of your library (they'll have to convert their code too, you know).
So, here's the verdict - if you're going to do it, then do it *now*. Otherwise, just tell people to ST(F)U and that you will never put it in a namespace.
Personally, I like namespaces and I use them a lot in my code.
-
The Dev. Team will discuss discuss about it tomorrow.
Thanks for your suggestions ;)
-
let us know how did you decided 8)
-
I made this choice of not using namespaces when I started to write the library, for various reasons (mainly a personal style, there is no particular technical reason).
Now, I'm ok to change it, but as it's an important decision I need stronger arguments. Not only "it's C++ philosophy" or "namespaces are cute" ;)
-
1. you can use using namespace sf( so no need to write sf everytime)
2. as i see sfml is organized into more libs, even these libs can use their own namespace like sf::audio or sf::gfx, dont know if it will be good solution thought :?
3. you can see it nicer in IDE object browser! =)
4. yes namespaces are cute :)
..sorry if i mistaked smth, i just downloaded sfml and now getting it to work on my linux :D
-
The main advantage of namespace would be the Koenig Lookup !
It would allow developers to do not break C++ idioms, for example massive utilisation of swap ! Users would do not have to use something like sfSwap, which is really NOT cute, and without having to pollute global namespace with another swap overload !
As lubos said, lot's of tools use namespace for easier navigation. See the SFML doxygen generated documentation : every class begin with S, it's not a really good organisation, it's not absolutely bad, but not perfect through.
-
The strongest point for using namespaces is the 1st one from lubos post - if you don't like the prefix, just add using in your file and you can write code without it.
I also agree with Aszarsha, that the documentation would look nicer without the prefix.
BTW, it is quite easy to make the old code work with the namespace - all you need is a few typedefs. Of course the right thing to do is to change all of the code. But the lazy ones can simply use typedefs... :)
-
Hello there,
since this lib is exactly what i have been looking for for quite some time,
I am really interested in making this lib as good as possible.
So here are my 5 (or whatever) cent.
(I am a professional C++ developer and have some experience with this stuff.)
Using namespaces definitely gives the whole thing a more professional appearance . Every major C++ API out there has its own namespaces and if u want this to become the next SDL maybe even used in commercial titles this is absolutely essential.
Of course, there are real, actual, tangible reasons for it:
1. write less if you use "using namespace xyz"
2. avoid collisions, even when using the namespace, by using fully qualified names.
3. it documents intent: If u have namespaces like sf::audio etc it serves well as a form of documentation.
4. makes code more navigable in IDEs.
5. etc. as has been said by others
So plz. do it and do it NOW.
regards, Oliver
-
I agree; namespaces are cleaner and have all of the advantages given above, and they would help adoption for sure.
What I suggest is moving everything into the 'sf' namespace (or even 'sfml' would be better), then creating sub-namespaces for each package, and move the appropriate types into those. Then you can keep around a compatibility header that typedefs all of the namespace-correct versions into the old prefix-style versions; that keeps code changes to a minimum for those that don't want to have to change all the code they've already written just yet.
I would do it, but I'm in the middle of trying to move to the SF bay area to start a new job at a movie VFX studio. :D I am definitely interested in contributing to this project. (I'd love to help with or see Gtk+ integration, as well as a Tao Framework package corresponding to this or some other .NET interface so you get exposure from that side of the fence.)
-
Ok, it seems my library won't be as good as I want until it uses namespaces... ;)
I'll add it ASAP and make a new release.
Thank you for convincing me.
-
Every major C++ API out there has its own namespaces and if u want this to become the next SDL maybe even used in commercial titles this is absolutely essential.
I may not have used SDL for awhile but last I remembered there was no namespaces needed to be used on my side. When I last used DirectX I also don't remember a namespace required to be used, and from what OpenGL code I have seen there also is not a single namespace declaration required from the API.
Bad arguement.
Of course, there are real, actual, tangible reasons for it:
1. write less if you use "using namespace xyz"
Hold on.....you call yourself a professional developer, yet you recommend people to do "using namespace namespace-name"? :shock:
-
I may not have used SDL for awhile but last I remembered there was no namespaces needed to be used on my side. When I last used DirectX I also don't remember a namespace required to be used, and from what OpenGL code I have seen there also is not a single namespace declaration required from the API.
Bad arguement.
Sorry SDL is C code the same goes for OpenGL. Namespaces are a C++ construct so do not mix up languages please. I can't talk about directX since i don't use it.
Hold on.....you call yourself a professional developer, yet you recommend people to do "using namespace namespace-name"? Shocked
whats wrong with using namespace?
-
yup directX is c++, and no namespaces there(iirc)..
this is going to be war.. prepare to battle :D
-
better don't start a war, I'm not sure if anyone wants to use DirectX as a good example how a lib should look like :wink:
-
better don't start a war, I'm not sure if anyone wants to use DirectX as a good example how a lib should look like :wink:
yep, peace, but look at most of the modern commercial games out there..its directX :cry:
-
yep your right, its widely used, but also widely hated for its API ;-).
-
Hold on.....you call yourself a professional developer, yet you recommend people to do "using namespace namespace-name"? Shocked
whats wrong with using namespace?
It is only wrong if you add it somewhere at the top of a header that everyone else will include a lot. There is nothing wrong with using namespace in cpp files (file scope) or better yet - inside classes or functions.
-
Yeah, generally the rule of thumb is to not put 'using namespace blahblah' into global scope, unless it is in a cpp file (and even then you might consider only doing it in function or class scope as suggested by PM).
On a game project I'm working on at a certain huge game development publisher, that's the rule we adopted for our team. We have mandated that we namespace-ify all of our code, but we have forbidden 'using' statements in header files except where you can restrict it to a specific scope. All of the intellisense-type tools and whatnot then make navigating namespaces to find identifiers really easy, and it makes for quick identification of where code logically fits into modules and sub-modules.
For C APIs, they use prefixes on their types and functions because, well, there weren't namespaces to do that job even better. For DirectX, it was first developed back when there was no namespace support in C++, and worse, it had to conform to the COM interfaces (which probably didn't easily allow themselves to be put into namespaces, at least when they were first introduced to Visual C++).
-
For DirectX, it was first developed back when there was no namespace support in C++, and worse, it had to conform to the COM interfaces (which probably didn't easily allow themselves to be put into namespaces, at least when they were first introduced to Visual C++).
I remember doing some research about COM. The main idea about it is that you can create a COM object in any language that supports COM, and then you (or others) can use that object with any language that supports COM. And there is actually a lot of languages that support it - C++, C, Assembler, Pascal (Delphi) and many more. So, to make it work on all of the languages, they had to skip support for some features (like namespaces).
-
I'm just wondering why the main namespace is called sf and not sfml? sfml is more descriptive in my opinion.
-
Because it's shorter, which is crucial because it prefixes every type name.
-
Ok.