c++ - Why "using namespace" directive is accepted coding practice in C#? -
i curious know why "using namespace" directive acceptable in c#, though in c++ not. aware c++ , c# different, guess c++ , c# come same family, , should using same ideas namespace resolution. c++ , c# both have alias keyword around namespace clash.
can point me, not reading between lines in c# makes acceptable use "using namespace" directive, , avoid problems c++ cannot.
in c++, if write using namespace
in header, in effect includes header. makes pretty unusable in headers. @ point, might avoid (at global scope) in .cpp files well, if sake of consistency, , make moving implementations between .h , .cpp easier.
(note locally scoped using namespace
- i.e. within function - considered fine; it's don't verbosity much)
in c#, there nothing #include
, , scope of using
directive never span beyond single .cs file. it's pretty safe use everywhere.
the other reason design of standard library. in c++, have std
(well, few more underneath it, used). in c#, have gems such system.collections.generic
, extremely verbose that's used commonly. it's more painful avoid using
in c# in c++.
to sum up, while c# , c++ share common design, on matter of code modularity (i'd assign headers, modules, namespaces group), design different.
Comments
Post a Comment