Coffeehouse Thread

12 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

global:: and other weird constructs

Back to Forum: Coffeehouse
  • User profile image
    littleguru

    Who did ever use global:: in C#? I wonder why they put this thing in... And what makes it even worser, is that a lot of the VS generated code uses this "thing" too...

    What is your top worst keyword/construct in a language (programming language Tongue Out)?

  • User profile image
    AndyC

    littleguru wrote:

    What is your top worst keyword/construct in a language (programming language )?


    The whole = and == thing in C, stupid stupid stupid. How many lost hours of programming are down to not using something slightly more sensible as an assignment operator?

  • User profile image
    Sven Groot

    littleguru wrote:
    Who did ever use global:: in C#?

    Not in C#, but I have used it once in VB (Global). I think it was in an ASP.NET project. I had some class in App_Code, and some local variable of the same name as the class. I needed to access a static member of that class. Soo I put Foo.Bar and it warns me I'm using an instance to access a static member. Normally you could qualify with a namespace, but this class wasn't explicitly in a namespace and since it was an ASP.NET project there's no implicit default namespace either (I think). So I ended up using Global.Foo.Bar which worked.

  • User profile image
    littleguru

    I don't understand why they added two :: after the global and not a . as usual?

  • User profile image
    leighsword

    littleguru wrote:
    Who did ever use global:: in C#? I wonder why they put this thing in... And what makes it even worser, is that a lot of the VS generated code uses this "thing" too...

    What is your top worst keyword/construct in a language (programming language )?

    Everything is an object in C#, so there 'should' no Global varibales in C#.

    Because ':' used to introduce a list of items, add two '::' may for avoid mistype that may waste our time, you know it's very slowly to show the global member list.

  • User profile image
    littleguru

    leighsword wrote:
    
    littleguru wrote: Who did ever use global:: in C#? I wonder why they put this thing in... And what makes it even worser, is that a lot of the VS generated code uses this "thing" too...

    What is your top worst keyword/construct in a language (programming language )?

    Everything is an object in C#, so there 'should' no Global varibales in C#.

    Because ':' used to introduce a list of items, add two '::' may for avoid mistype that may waste our time, you know it's very slowly to show the global member list.


    Hi leighsword. This is not a global variable. It seems as it is just there to support intellisense. As this is. It isn't even included in the compiled assembly.

    It's a weird something from some time, I guess.

  • User profile image
    leighsword

    littleguru wrote:
    
    leighsword wrote: 
    littleguru wrote: Who did ever use global:: in C#? I wonder why they put this thing in... And what makes it even worser, is that a lot of the VS generated code uses this "thing" too...

    What is your top worst keyword/construct in a language (programming language )?

    Everything is an object in C#, so there 'should' no Global varibales in C#.

    Because ':' used to introduce a list of items, add two '::' may for avoid mistype that may waste our time, you know it's very slowly to show the global member list.


    Hi leighsword. This is not a global variable. It seems as it is just there to support intellisense. As this is. It isn't even included in the compiled assembly.

    It's a weird something from some time, I guess.

    well, my English expression is not good, but my logic is as clear as a developer.
     
    :: is for show the Global variables or functions;
    and there no global stuff;
    so :: is unnecessary in here.

  • User profile image
    Sven Groot

    littleguru wrote:
    Hi leighsword. This is not a global variable. It seems as it is just there to support intellisense. As this is. It isn't even included in the compiled assembly.

    Global is not an object. It's a keyword, so naturally it's not in any assembly. It says the context for what follows is global scope. It can in some cases be necessary, like the VB example I indicated above.

    Consider the following (quite artificial, I realize that) example:

    namespace Foo.System
    {
       class String
       {
       }
    }

    namespace Foo
    {
       class Bar
       {
          private System.String _baz;
       }
    }

    What type is Bar._baz now? It's Foo.System.String, not System.String. So how would you specify you do want System.String? Simple: global::System.String. Without global, there's no good way to do this. You could do "using System" (at the top of the file, inside namespace Foo wouldn't work obviously) and just use String, but what if Foo.System is also imported? Then the reference is ambiguous. You could still solve it by aliasing the global System namespace (using System = S or whatever) then qualifying the String reference with the alias, but frankly, I would prefer global.

    So yes, it is esoteric, but it does have a use. Generated code uses it a lot so they're sure they get the object they want, not a different one because of lookup order.

    Why they used the :: I don't know. Probably to make it look like the C++ scope resolution operator (which can serve the same purpose if you put nothing in front of it, e.g. ::Foo references a global Foo in C++ no matter what the context), but C# replaced :: with a . in all other places where C++ uses it, so I really don't know why they used it here.

  • User profile image
    Human​Compiler

    AndyC wrote:
    
    littleguru wrote:
    What is your top worst keyword/construct in a language (programming language )?


    The whole = and == thing in C, stupid stupid stupid. How many lost hours of programming are down to not using something slightly more sensible as an assignment operator?


    Could it be because we have the same personality type that I totally agree?  That said, I'm quite used to it.  Started off in Pascal which is the opposite.  := being the assignment operator and = being the comparison operator.  Good times.  Tongue Out

  • User profile image
    littleguru

    Sven Groot wrote:
    
    littleguru wrote: Hi leighsword. This is not a global variable. It seems as it is just there to support intellisense. As this is. It isn't even included in the compiled assembly.

    Global is not an object. It's a keyword, so naturally it's not in any assembly. It says the context for what follows is global scope. It can in some cases be necessary, like the VB example I indicated above.


    Agreed.

    I have read a few minutes ago that you can put a class directly into the global namespace by enclosing it in the "global" namespace:

    namespace global
    {
           public class Foo() ...
    }

    This is so weird. Namespaces should start with an upper case but this one starts with a lower case... Then the two :, which makes it look like C++ and not C#. Weird stuff.

  • User profile image
    Lee_Dale

    ive never actually liked the :: global accessor in C++ Perplexed

  • User profile image
    billh

    I would have to agree that the whole "=" and "==" issue caused me plenty of problems when I was first starting out in C.

    It's interesting to note, though, that in several procedural languages of old (some of which I used heavily many years ago) you could only use global variables.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.