Skip to content

Move global declarations to a namespace #1401

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

sergeuz
Copy link
Member

@sergeuz sergeuz commented Oct 4, 2017

Problem

Particle APIs get pulled into the global namespace and cause conflicts with an application code. This behavior cannot be overridden by application developers.

Solution

Add PARTICLE_NO_GLOBAL_NAMESPACE macro that can be defined by applications to avoid having Particle APIs declared in the global namespace.

Note: This PR doesn't attempt to move all current APIs to the particle namespace, and many existing classes and functions are still declared in the global namespace directly. I suggest we start moving such declarations to namespaces iteratively, on occasion.

Steps to Test

wiring/api test should compile successfully.

Example App

#define PARTICLE_NO_GLOBAL_NAMESPACE

#include "Particle.h"

// I just need my own WiFi class
class WiFi {
};

void test(WiFi&) {
}

References

  • fixes #1267
  • [ch8449]

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@sergeuz sergeuz added this to the 0.7.0 milestone Oct 4, 2017
@sergeuz sergeuz requested a review from m-mcgowan October 4, 2017 22:12
@monkbroc
Copy link
Member

monkbroc commented Oct 5, 2017

That's a good idea. 👍

Due to how the wiring preprocessor works, it needs to be documented that both the new define and the Particle include need to be added. For a refresher on how the preprocessor works, see the preprocessor description in the docs.

For example this wouldn't work in the Web IDE:

#define PARTICLE_NO_GLOBAL_NAMESPACE
class WiFi {};

This would work:

#define PARTICLE_NO_GLOBAL_NAMESPACE
#include "Particle.h"
class WiFi {};

We also document using #include "Particle.h" not #include "application.h". I know they are equivalent but that's the documentation choice right now. (BRETT: Edited the example app with this)

@sergeuz
Copy link
Member Author

sergeuz commented Oct 5, 2017

That's a good point, Julien. Good to know that the Web IDE is smart enough to not pre-include any header files unconditionally.

@m-mcgowan
Copy link
Contributor

It would be nice to see tests affirming that global symbols such as Message and Promise are no longer taken by default.

@m-mcgowan m-mcgowan modified the milestones: 0.7.0, 0.8.0 Nov 21, 2017
@m-mcgowan m-mcgowan modified the milestones: 0.8.0, 0.8.0-rc.3 Jan 18, 2018
@technobly technobly modified the milestones: 0.8.0-rc.3, 0.8.0-rc.4 Apr 3, 2018
@technobly technobly modified the milestones: 0.8.0-rc.4, 0.8.0-rc.5 May 6, 2018
@technobly technobly removed this from the 0.8.0-rc.5 milestone May 31, 2019
@m-mcgowan
Copy link
Contributor

Is this a safe change? is it something we should queue up for the 2.x release in case there are breaking changes? I would like to see the API test suite expanded to cover the entire API and become our definitive reference of what is in the global and particle namespaces.

@m-mcgowan m-mcgowan removed their request for review June 7, 2019 22:21
@monkbroc
Copy link
Member

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

Successfully merging this pull request may close these issues.

Move global defines to a namespace.
4 participants