namespaces

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tem

    namespaces

    Are these equivalent?

    ------------------
    using System;

    namespace SomeNamespace
    {

    }

    -------------------
    namespace SomeNamespace
    {
    using System;
    }
  • Jon Skeet [C# MVP]

    #2
    Re: namespaces

    On May 6, 9:11 am, "Tem" <tem1...@yahoo. comwrote:
    Are these equivalent?
    >
    ------------------
    using System;
    >
    namespace SomeNamespace
    {
    >
    }
    >
    -------------------
    namespace SomeNamespace
    {
    using System;
    >
    }
    Not quite, or at least not always.See


    Jon

    Comment

    • Brian Gideon

      #3
      Re: namespaces

      On May 6, 3:11 am, "Tem" <tem1...@yahoo. comwrote:
      Are these equivalent?
      >
      ------------------
      using System;
      >
      namespace SomeNamespace
      {
      >
      }
      >
      -------------------
      namespace SomeNamespace
      {
          using System;
      >
      >
      >
      }
      In that particular case, yes. But, like Jon said, it can make a
      difference. I discovered this oddity and posted it in this group
      quite some time ago hoping someone could point me to the section in
      the specification that discusses it. I did some scouring of my own
      and I believe the crucial section is 10.7 (ECMA) where it says:

      "The scope of a namespace member declared by a namespace-member-
      declaration within a namespace-declaration whose fully qualified name
      is N, is the
      namespace-body of every namespace-declaration whose fully qualified
      name is N
      or starts with N, followed by a period."

      Clear as mud huh?

      Comment

      • Brian Gideon

        #4
        Re: namespaces

        On May 6, 5:14 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
        Not quite, or at least not always.Seehttp://blogs.msdn.com/ericlippert/archive/2007/06/25/inside-or-outsid...
        >
        Jon
        Don't you have a web page of C# oddities? This would almost certainly
        qualify to be listed!

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: namespaces

          Brian Gideon <briangideon@ya hoo.comwrote:
          On May 6, 5:14 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
          Not quite, or at least not always.Seehttp://blogs.msdn.com/ericlippert/archive/2007/06/25/inside-or-outsid...
          Don't you have a web page of C# oddities? This would almost certainly
          qualify to be listed!
          I've got this one:

          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


          if that's what you mean. Yes, I could add it - along with a whole bunch
          I suspect I've got queued up somewhere!

          --
          Jon Skeet - <skeet@pobox.co m>
          Web site: http://www.pobox.com/~skeet
          Blog: http://www.msmvps.com/jon.skeet
          C# in Depth: http://csharpindepth.com

          Comment

          • Brian Gideon

            #6
            Re: namespaces

            On May 6, 12:44 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
            Brian Gideon <briangid...@ya hoo.comwrote:
            On May 6, 5:14 am, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
            Not quite, or at least not always.Seehttp://blogs.msdn.com/ericlippert/archive/2007/06/25/inside-or-outsid...
            >
            Don't you have a web page of C# oddities?  This would almost certainly
            qualify to be listed!
            >
            I've got this one:
            >
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            >
            if that's what you mean. Yes, I could add it - along with a whole bunch
            I suspect I've got queued up somewhere!
            >
            --
            Jon Skeet - <sk...@pobox.co m>
            Web site:http://www.pobox.com/~skeet 
            Blog:http://www.msmvps.com/jon.skeet
            C# in Depth:http://csharpindepth.com
            Yep, that's the link I was referring too.

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: namespaces

              Brian Gideon <briangideon@ya hoo.comwrote:
              I've got this one:

              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.


              if that's what you mean. Yes, I could add it - along with a whole bunch
              I suspect I've got queued up somewhere!
              >
              Yep, that's the link I was referring too.
              Okay - I'll try to remember to do it soonish. (At the very least I'll
              add an HTML comment to remind me :)

              --
              Jon Skeet - <skeet@pobox.co m>
              Web site: http://www.pobox.com/~skeet
              Blog: http://www.msmvps.com/jon.skeet
              C# in Depth: http://csharpindepth.com

              Comment

              • Brian Gideon

                #8
                Re: namespaces

                Here's an example teaser. It demonstrates how the placement of the
                using statement can create an even more peculiar effect than what the
                blog elluded to. Notice how the inner placed version imports the A.B
                type even though it was contained within A.C. That means it is doing
                more than giving preference to a nested namespace. It must be
                *walking up* the containing namespace path as well as demonstrated
                below. Peculiar indeed!

                using B; // Try it here

                namespace A.C
                {
                using B; // and then here next!

                public class Program
                {
                public static void Main(string[] args)
                {
                Foo.DoSomething ();
                }
                }
                }

                namespace A.B
                {
                public class Foo
                {
                public static void DoSomething()
                {
                Console.WriteLi ne("A.B.Foo.DoS omething()");
                }
                }
                }

                namespace B
                {
                public class Foo
                {
                public static void DoSomething()
                {
                Console.WriteLi ne("B.Foo.DoSom ething()");
                }
                }
                }


                Comment

                • Jon Skeet [C# MVP]

                  #9
                  Re: namespaces

                  Brian Gideon <briangideon@ya hoo.comwrote:
                  Here's an example teaser. It demonstrates how the placement of the
                  using statement can create an even more peculiar effect than what the
                  blog elluded to. Notice how the inner placed version imports the A.B
                  type even though it was contained within A.C. That means it is doing
                  more than giving preference to a nested namespace. It must be
                  *walking up* the containing namespace path as well as demonstrated
                  below. Peculiar indeed!
                  Ooh, that will certainly make my life easier. Thanks very much :)

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  Web site: http://www.pobox.com/~skeet
                  Blog: http://www.msmvps.com/jon.skeet
                  C# in Depth: http://csharpindepth.com

                  Comment

                  • Tem

                    #10
                    Re: namespaces

                    "The scope of a namespace member declared by a namespace-member-
                    declaration within a namespace-declaration whose fully qualified name
                    is N, is the namespace-body of every namespace-declaration whose fully
                    qualified
                    name is N or starts with N, followed by a period."

                    so which one is better? or perferred?


                    "Brian Gideon" <briangideon@ya hoo.comwrote in message
                    news:f4cde640-6059-489b-a3ec-b5e6c455d5a1@l4 2g2000hsc.googl egroups.com...
                    On May 6, 3:11 am, "Tem" <tem1...@yahoo. comwrote:
                    Are these equivalent?
                    >
                    ------------------
                    using System;
                    >
                    namespace SomeNamespace
                    {
                    >
                    }
                    >
                    -------------------
                    namespace SomeNamespace
                    {
                    using System;
                    >
                    >
                    >
                    }
                    In that particular case, yes. But, like Jon said, it can make a
                    difference. I discovered this oddity and posted it in this group
                    quite some time ago hoping someone could point me to the section in
                    the specification that discusses it. I did some scouring of my own
                    and I believe the crucial section is 10.7 (ECMA) where it says:

                    "The scope of a namespace member declared by a namespace-member-
                    declaration within a namespace-declaration whose fully qualified name
                    is N, is the
                    namespace-body of every namespace-declaration whose fully qualified
                    name is N
                    or starts with N, followed by a period."

                    Clear as mud huh?

                    Comment

                    • clintonG

                      #11
                      Re: namespaces

                      Get the tattoo:
                      THE MOST READABLE CODE WINS.

                      "Tem" <tem1232@yahoo. comwrote in message
                      news:OqplAnZsIH A.4392@TK2MSFTN GP03.phx.gbl...
                      "The scope of a namespace member declared by a namespace-member-
                      declaration within a namespace-declaration whose fully qualified name
                      is N, is the namespace-body of every namespace-declaration whose fully
                      qualified
                      name is N or starts with N, followed by a period."
                      >
                      so which one is better? or perferred?
                      >
                      >
                      "Brian Gideon" <briangideon@ya hoo.comwrote in message
                      news:f4cde640-6059-489b-a3ec-b5e6c455d5a1@l4 2g2000hsc.googl egroups.com...
                      On May 6, 3:11 am, "Tem" <tem1...@yahoo. comwrote:
                      >Are these equivalent?
                      >>
                      >------------------
                      >using System;
                      >>
                      >namespace SomeNamespace
                      >{
                      >>
                      >}
                      >>
                      >-------------------
                      >namespace SomeNamespace
                      >{
                      >using System;
                      >>
                      >>
                      >>
                      >}
                      >
                      In that particular case, yes. But, like Jon said, it can make a
                      difference. I discovered this oddity and posted it in this group
                      quite some time ago hoping someone could point me to the section in
                      the specification that discusses it. I did some scouring of my own
                      and I believe the crucial section is 10.7 (ECMA) where it says:
                      >
                      "The scope of a namespace member declared by a namespace-member-
                      declaration within a namespace-declaration whose fully qualified name
                      is N, is the
                      namespace-body of every namespace-declaration whose fully qualified
                      name is N
                      or starts with N, followed by a period."
                      >
                      Clear as mud huh?

                      Comment

                      • Brian Gideon

                        #12
                        Re: namespaces

                        On May 9, 12:58 am, "Tem" <tem1...@yahoo. comwrote:
                        so which one is better? or perferred?
                        I'm not sure it matters really. I guess there is a strong argument
                        for putting the using statement outside the namespace declaration
                        since that yields the most intuitive result.

                        I actually stumbled upon this on my own several years ago because I
                        was putting the using statement inside the namespace declaration and
                        actually had this strange situation (which I posted as an example in
                        this thread in a response to Jon) occur once. It was a very difficult
                        bug to find because, at that time, I felt like the behavior of the
                        using statement was so fundamentally established to me that I didn't
                        even entertain the possiblity that it was the root of my problem. I
                        was lead down the wrong path of thinking there was some obscure bug in
                        the compiler.

                        Comment

                        Working...