c++ - namespace vs naming convention -
actually i'm starting new small project own , reading naming conventions. independent of coding style preferred, google coding style or hungarian notation (in opinion system hungarian style (even if think not style) not apps style) or other styles i'm not mentioned, though using naming convention or make namespaces. i've read post.
my attention on inheritance.
google example:
class myclassinterface { int some_stuff() = 0; }; class myclassa : myclassinterface { int some_stuff() { return 1; } }; class myclassb : myclassinterface { int some_stuff() { return 2; } };
now idea using namespaces:
namespace { namespace interface { class class { int some_stuff() = 0; }; } // namespace interface namespace { class class : interface::class { int some_stuff() { return 1; } }; } // namespace namespace b { class class : interface::class { int some_stuff() { return 2; } }; } // namespace b } // namespace
the advantage of kind of naming can seen in example:
using namepsace my; void foo(interface::class lala) { // something; } // ... int main() { using namespace a; class bar; foo(bar); b::class bar2; foo(bar2); }
now can type using namespace
, use prefered one, other child classes still reachable there namespaces.
now question is, idea, or there disadvantages don't mentioned yet?
edit:
i use
namespace { namespace interface { class class { int some_stuff() = 0; }; } // namespace interface class classa : interface::class { int some_stuff() { return 1; } }; class classb : interface::class { int some_stuff() { return 2; } }; } // namespace
to not nest namespaces.
addendum
i'm not sure if stackoverflow right place put question in, on programmers there not tag naming-convention (but naming-standards). , there not lot of discussion on namespaces , naming-conventions. if it's wrong move question.
i think rule is: use namespaces identify library (the contents of library). use nested namespaces in specific cases (cases contents of nested namespace considered library itself).
an example of standard library: provides functionality through std
namespace, , (for example) provides chrono library (it viewed library itself) through std::chrono
namespace. other example boost , libraries.
Comments
Post a Comment