Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: why not using a namespace  (Read 21967 times)

0 Members and 1 Guest are viewing this topic.

lubos

  • Newbie
  • *
  • Posts: 17
    • ICQ Messenger - 385328377
    • MSN Messenger - qwarmail@yahoo.co.uk
    • View Profile
why not using a namespace
« Reply #15 on: August 17, 2007, 02:07:27 pm »
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

Aszarsha

  • Full Member
  • ***
  • Posts: 200
    • MSN Messenger - aszarsha@gmail.com
    • View Profile
why not using a namespace
« Reply #16 on: August 17, 2007, 02:26:13 pm »
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.

PM

  • Newbie
  • *
  • Posts: 18
    • View Profile
why not using a namespace
« Reply #17 on: August 17, 2007, 03:59:46 pm »
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... :)

lordolin

  • Newbie
  • *
  • Posts: 2
    • View Profile
namespaces -- my 5 cent
« Reply #18 on: August 20, 2007, 08:20:10 pm »
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

Tecla

  • Newbie
  • *
  • Posts: 2
    • View Profile
why not using a namespace
« Reply #19 on: August 20, 2007, 10:52:39 pm »
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.)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
why not using a namespace
« Reply #20 on: August 21, 2007, 08:24:02 am »
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.
Laurent Gomila - SFML developer

ExcessNeo

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: namespaces -- my 5 cent
« Reply #21 on: August 21, 2007, 12:49:36 pm »
Quote from: "lordolin"
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.
 
Quote
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:

mweb

  • Newbie
  • *
  • Posts: 13
    • View Profile
why not using a namespace
« Reply #22 on: August 21, 2007, 01:06:28 pm »
Quote

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.

Quote

Hold on.....you call yourself a professional developer, yet you recommend people to do "using namespace namespace-name"? Shocked


whats wrong with using namespace?

lubos

  • Newbie
  • *
  • Posts: 17
    • ICQ Messenger - 385328377
    • MSN Messenger - qwarmail@yahoo.co.uk
    • View Profile
why not using a namespace
« Reply #23 on: August 21, 2007, 01:29:11 pm »
yup directX is c++, and no namespaces there(iirc)..
this is going to be war.. prepare to battle :D

mweb

  • Newbie
  • *
  • Posts: 13
    • View Profile
why not using a namespace
« Reply #24 on: August 21, 2007, 01:55:23 pm »
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:

lubos

  • Newbie
  • *
  • Posts: 17
    • ICQ Messenger - 385328377
    • MSN Messenger - qwarmail@yahoo.co.uk
    • View Profile
why not using a namespace
« Reply #25 on: August 21, 2007, 02:23:50 pm »
Quote from: "mweb"
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:

mweb

  • Newbie
  • *
  • Posts: 13
    • View Profile
why not using a namespace
« Reply #26 on: August 21, 2007, 02:28:49 pm »
yep your right, its widely used, but also widely hated for its API ;-).

PM

  • Newbie
  • *
  • Posts: 18
    • View Profile
why not using a namespace
« Reply #27 on: August 21, 2007, 04:14:48 pm »
Quote from: "mweb"
Quote

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.

Tecla

  • Newbie
  • *
  • Posts: 2
    • View Profile
why not using a namespace
« Reply #28 on: August 25, 2007, 08:22:21 am »
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++).

PM

  • Newbie
  • *
  • Posts: 18
    • View Profile
why not using a namespace
« Reply #29 on: August 25, 2007, 08:52:17 am »
Quote from: "Tecla"
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).