Re: Can't use using in method???

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 04/01/04


Date: Thu, 1 Apr 2004 08:14:13 +0100

Julie <julie@nospam.com> wrote:
> > Why, exactly?
>
> I'm finding it hard to justify -- essentially it renders namespaces useless to
> just strip away the namespace w/ a using statement.

It doesn't render them useless at all. Namespaces prevent name
collision. If you have two classes with the same name in different
namespaces, you can always disambiguate by using the full name, which
you couldn't do without namespaces. The "using" statement just allows
you to avoid typing the full name when there *aren't* any collisions.
 
> In C++, you can use a using within function scope, that is why I was asking. I
> had never used it, but I'm finding all sorts of problems w/ the global using
> directive and name clashes due to the stripping of the namespace.

What sort of problems? How often is this occurring? I ask because I
only run into it once in a blue moon...

> I'll probably just stop 'using' all together, seems that it would make for
> longer names, but explicitly more clear code.

I think you'll find you either change your mind quickly, or if you're
working with others they'll petition you to change your mind. There's a
good reason why basically no-one does this.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: [RFC/PATCH] revoke/frevoke system calls V2
    ... fuser is quite easy to race, it doesn't handle all sorts of corner cases ... like namespaces either. ...
    (Linux-Kernel)
  • The BTS. and FILE. namespaces
    ... In the EXPRESSION shapes we get access to all sorts of weird and wonderful ... these namespaces and is it possible to use them outside an orchestration (for ... Prev by Date: ...
    (microsoft.public.biztalk.general)
  • Re: Namespaces in PHP5, removed?
    ... > where you link in binary libraries and there's no other workaround for name ... With PHP you can just rename the class/function. ... know that a name collision exists to begin with. ... alternative to namespaces is a class naming convention, ...
    (comp.lang.php)
  • Re: why?
    ... department, time, number of classes, namespaces, functions, etc have to do ... Puts me in mind of the scene from "Dead Poets' Society" where Robin ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Index a #define string
    ... in *many* cases the language provides superior alternatives. ... >> organize names, but they do not, at a language level, protect them. ... >> The only things that stop name collision are ... > Namespaces do not exist to protect from name collisions. ...
    (comp.lang.cpp)