Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example rescope #46

Closed
wants to merge 1 commit into from
Closed

Example rescope #46

wants to merge 1 commit into from

Conversation

Algias
Copy link

@Algias Algias commented May 8, 2020

This is an example of re-scoping the raylib library and the raylib-cpp classes. This sort of thing has to be done across all files as there are a large amount of dependencies within one another.

What this achieves is that it separates the raylib and raylib-cpp functionality into separate namespaces to prevent pollution of the global namespace with raylib functions i.e raylib functions will not be called "on-accident" by calling or utilizing raylib-cpp api.

Currently, raylib functions are callable from the global namespace and thus can circumvent going through the raylib-cpp class. This can be seen in many of the examples where a mixture of raylib and raylib-cpp api are used despite raylib-cpp equivalents existing.

This is not the most elegant solution, but I had trouble with getting nested-namespaces working properly due to the ambiguity between the class and struct names.

Ultimately I believe this is just a matter of philosophy regarding the wrapper design, and really is mostly trivial.

@RobLoach
Copy link
Owner

Interesting idea. Would increase verbosity, and save from namespace collisions. You're right about it being needed to happen across all files. Mind if we keep this PR open to get some other's thoughts on it?

@Hamondorf
Copy link

I would definitely like to see this addition if possible.

@Algias
Copy link
Author

Algias commented Sep 6, 2020

I'll take a look again in the near future and see if I can make it happen!

@RobLoach
Copy link
Owner

I'm unsure how this would be reflected in other spaces. While it does make sense, it is changing how people would use the main raylib API, so I'm going to close this for now. Thanks!

@RobLoach RobLoach closed this Jan 27, 2021
@marinedalek
Copy link

I'd tend to agree with Algias's suggestion here. If raylib-cpp is to be an "idiomatic" C++ wrapper, then it ought not to transitively dump names into the global namespace when included. My opinion is that changing how people (i.e. C++ users) use Raylib is the whole point of such a wrapper. Any and all functionality should be presented in the raylib:: namespace and the choice of whether to expose that in the global namespace left up to the consumer of the header.

My own preference would be for the low-level C raylib functions to be present in a nested namespace, perhaps raylib::impl:: , to signal to users that they should be using the high-level OOP/RAII constructs rather than the C underpinning. Even then, a determined user would be able to use the header in the current "mixed" mode by adding using namespace raylib::impl; to their source file, while everyone else enjoyed a clean, unpolluted global namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants