CrossTheRoadElec / Phoenix-api

CTRE Phoenix language API (targets FIRST Robotics Competition, Linux, RaspPi, Windows)
Other
39 stars 28 forks source link

Hoisting all of ctre clutters the global namespace #23

Closed duane701 closed 6 years ago

duane701 commented 6 years ago

https://github.com/CrossTheRoadElec/Phoenix-frc-lib/blob/9704468db863a6e12d38feb60ba01f0cb050de49/cpp/include/ctre/Phoenix.h#L25

Putting all of the ctre symbols into the global namespace seems a little heavy. I've had to put a few classes into our own namespace (which admittedly we should already be doing).

FRC has introduced the frc namespace. Can I expect that ctre will eventually keep the symbols in the ctre namespace? For example, hoisting into ctre would be useful.

ozrien commented 6 years ago

The Phoenix header, by design, includes all relevant namespaces for our products.

Typically including namespaces in a header is taboo, as it can create ambiguities in common class names. However in FRC, C++ namespaces are a trap for many FRC teams. Also the intelli-sense features in Eclipse (C++) do not aid in helping the developer include the correct namespace (prefix with scope resolution operator, or inserting the using command at top of C++ file).

So the compromise is, if you don't know what you are doing (inexperienced FRC students), include Phoenix.h If you understand namespaces, then include the feature specific header and optionally include the "using namespace" at the top of your C++ module.

This is also mentioned here... https://github.com/CrossTheRoadElec/Phoenix-Documentation#c---how-to-intellisensewhat-header