Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Aaaarg....use the namespace

Aaaarg....use the namespace

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpc++javaphp
31 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    That's not "style", but a "preference"; the difference is that one needs arguments, the other doesn't. People who prefer the long naming should try prefixing everything with "global::".

    Bastard Programmer from Hell :suss:

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #8

    Eddy Vluggen wrote:

    prefixing everything with "global::".

    I tried that, briefly.

    L 1 Reply Last reply
    0
    • S Sentenryu

      Actually, it's less time. As the compiler already knows in what namespace the StringBuilder is, he doesn't need to search all the used namespaces... But this difference is imperceptible.

      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #9

      Sentenryu wrote:

      the compiler already knows in what namespace the StringBuilder is

      How?

      S 1 Reply Last reply
      0
      • S Sentenryu

        Personally, I always import, unless there is already something with the same name imported. But it's a matter of taste.

        I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #10

        Sentenryu wrote:

        I always import

        But that's not what the using directive does. There is no "import" in C# -- the closest to that is references.

        S 1 Reply Last reply
        0
        • M Manfred Rudolf Bihy

          Just a little reminder: This is the "Hall Of Shame" and not he "Hall Of Bugs". There is no good reason to clutter ones code with superflous repetitions of the namespace prefixing the StringBuilder, except maybe when there is another implementation of StringBuilder floating around. Just my two cents! :)

          "With sufficient thrust, pigs fly just fine."

          Ross Callon, The Twelve Networking Truths, RFC1925

          S Offline
          S Offline
          Sentenryu
          wrote on last edited by
          #11

          I don't see the shame on this, this guy just like to write long names :|

          I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

          T 1 Reply Last reply
          0
          • P PIEBALDconsult

            Sentenryu wrote:

            I always import

            But that's not what the using directive does. There is no "import" in C# -- the closest to that is references.

            S Offline
            S Offline
            Sentenryu
            wrote on last edited by
            #12

            my teachers always said import here in Brazil, I ended up picking up the habit...

            I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

            1 Reply Last reply
            0
            • P PIEBALDconsult

              Sentenryu wrote:

              the compiler already knows in what namespace the StringBuilder is

              How?

              S Offline
              S Offline
              Sentenryu
              wrote on last edited by
              #13

              You specified it when you wrote System.Text.StringBuilder ...

              I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

              P 1 Reply Last reply
              0
              • S Sentenryu

                You specified it when you wrote System.Text.StringBuilder ...

                I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #14

                Ah, so perhaps you were agreeing with me. I see now that my statement was unclear and I have added clarification.

                S 1 Reply Last reply
                0
                • P PIEBALDconsult

                  Ah, so perhaps you were agreeing with me. I see now that my statement was unclear and I have added clarification.

                  S Offline
                  S Offline
                  Sentenryu
                  wrote on last edited by
                  #15

                  Yes yes, I really have bad time expressing this things on languages other than my own... (actually, even in my own language sometimes I've bad times trying to express my self... :( )

                  I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Eddy Vluggen wrote:

                    prefixing everything with "global::".

                    I tried that, briefly.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #16

                    PIEBALDconsult wrote:

                    I tried that, briefly.

                    ..a good idea, if you are paid per line written. It should feel comparably to explicitly stating that a member is "private", and prefixing everything possible with "this".

                    Bastard Programmer from Hell :suss:

                    P 1 Reply Last reply
                    0
                    • S Sentenryu

                      Personally, I always import, unless there is already something with the same name imported. But it's a matter of taste.

                      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #17

                      Sentenryu wrote:

                      But it's a matter of taste.

                      No, it's not. Bloating code is an offence. Three offences, you're out.

                      Bastard Programmer from Hell :suss:

                      B 1 Reply Last reply
                      0
                      • L Lost User

                        PIEBALDconsult wrote:

                        I tried that, briefly.

                        ..a good idea, if you are paid per line written. It should feel comparably to explicitly stating that a member is "private", and prefixing everything possible with "this".

                        Bastard Programmer from Hell :suss:

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #18

                        Eddy Vluggen wrote:

                        explicitly stating that a member is "private",

                        Which everyone should do. There should be no default access modifiers.

                        Eddy Vluggen wrote:

                        prefixing everything possible with "this".

                        Which I also do. Just because. :cool:

                        L 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          Eddy Vluggen wrote:

                          explicitly stating that a member is "private",

                          Which everyone should do. There should be no default access modifiers.

                          Eddy Vluggen wrote:

                          prefixing everything possible with "this".

                          Which I also do. Just because. :cool:

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #19

                          PIEBALDconsult wrote:

                          Which everyone should do. There should be no default access modifiers.

                          Why?

                          PIEBALDconsult wrote:

                          Which I also do. Just because. :cool:

                          The amount of symbols that you use to convey an idea would best be kept to a minimum.

                          Bastard Programmer from Hell :suss:

                          N 1 Reply Last reply
                          0
                          • L Lost User

                            PIEBALDconsult wrote:

                            Which everyone should do. There should be no default access modifiers.

                            Why?

                            PIEBALDconsult wrote:

                            Which I also do. Just because. :cool:

                            The amount of symbols that you use to convey an idea would best be kept to a minimum.

                            Bastard Programmer from Hell :suss:

                            N Offline
                            N Offline
                            Nagy Vilmos
                            wrote on last edited by
                            #20

                            No, you prefix the member if a class with this to prevent any ambiguity. The method or property on it's own only implies where it is. If I have this code:

                            class Thingy {
                            private int majig = 27;

                            void summit() {
                                if (majig > 42) {
                                  // clever code
                                }
                            }
                            

                            }

                            And I copy the test to another method, all bad things could happen:

                            void nuThang() {
                                // lots of code
                                int majig = 69;
                            
                                // lots more code
                                // copied:
                                if (majig > 42) {
                                  // clever code
                                }
                            }
                            

                            oops.


                            Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                            L P 2 Replies Last reply
                            0
                            • N Nagy Vilmos

                              No, you prefix the member if a class with this to prevent any ambiguity. The method or property on it's own only implies where it is. If I have this code:

                              class Thingy {
                              private int majig = 27;

                              void summit() {
                                  if (majig > 42) {
                                    // clever code
                                  }
                              }
                              

                              }

                              And I copy the test to another method, all bad things could happen:

                              void nuThang() {
                                  // lots of code
                                  int majig = 69;
                              
                                  // lots more code
                                  // copied:
                                  if (majig > 42) {
                                    // clever code
                                  }
                              }
                              

                              oops.


                              Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #21

                              Copy/paste is often an invitation not to check what you just pasted. Your example might be a nice example on why we introduced the DRY principle, but being this abstract, one can't be sure. But no, I'd not be bloating my code for the sake of "easy copies". If it's that re-usable, I'll take the time to make it a snippet. --edit;

                              Nagy Vilmos wrote:

                              No, you prefix the member if a class with this to prevent any ambiguity

                              ..the same kind of ambiguity that you have if you don't use the full name against a type, including it's namespace. Do you have global variables that clash with the names of the property/method that you're calling from the current object that you need to specify explicitly that you need the property/method from "this" object?

                              Bastard Programmer from Hell :suss:

                              1 Reply Last reply
                              0
                              • N Nagy Vilmos

                                No, you prefix the member if a class with this to prevent any ambiguity. The method or property on it's own only implies where it is. If I have this code:

                                class Thingy {
                                private int majig = 27;

                                void summit() {
                                    if (majig > 42) {
                                      // clever code
                                    }
                                }
                                

                                }

                                And I copy the test to another method, all bad things could happen:

                                void nuThang() {
                                    // lots of code
                                    int majig = 69;
                                
                                    // lots more code
                                    // copied:
                                    if (majig > 42) {
                                      // clever code
                                    }
                                }
                                

                                oops.


                                Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #22

                                Nagy Vilmos wrote:

                                you prefix the member if a class with this to prevent any ambiguity

                                Correct.

                                1 Reply Last reply
                                0
                                • S Sentenryu

                                  I don't see the shame on this, this guy just like to write long names :|

                                  I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                                  T Offline
                                  T Offline
                                  thatraja
                                  wrote on last edited by
                                  #23

                                  Sentenryu wrote:

                                  I don't see the shame on this, this guy just like to write long names :|

                                  :doh: Huh? I don't, read my message again. I don't want the repetitions so I just mentioned the namespace at the top & replaced things.

                                  thatraja

                                  FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
                                  HTML Marquee & its alternatives

                                  Nobody remains a virgin, Life screws everyone :sigh:

                                  S 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    I disagree, it's just code, the compiler doesn't care* and it's better to give the next developer too much information rather than too little. But could they have all shared one static instance? How often are these methods called? Are there threading issues? How big do the StringBuilders become? Can you estimate how big? If large, then pre-allocating enough memory or re-using existing instances can eliminate a lot of needless re-allocation. * However, I suspect that when you use the using directive** the compiler must have to spend some additional time looking them up. ** Qualification added for clarification.

                                    T Offline
                                    T Offline
                                    thatraja
                                    wrote on last edited by
                                    #24

                                    There I mentioned StringBuilder is just an example. I found many similar things like below.

                                    System.Diagnostics.Trace.Write
                                    System.Diagnostics.Trace.WriteLine
                                    System.Drawing.Color
                                    System.Configuration.Configuration
                                    System.IO.StreamWriter
                                    System.IO.StreamReader
                                    System.IO.FileInfo
                                    System.IO.FileStream
                                    System.IO.StringReader
                                    System.IO.StringWriter
                                    System.IO.TextReader
                                    System.IO.TextWriter
                                    System.Xml.XmlDocument
                                    etc.,
                                    ....
                                    ...
                                    ..
                                    .

                                    Why so much repetitions? After that some more 100s of replacements done. Namespace at top.

                                    thatraja

                                    FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
                                    HTML Marquee & its alternatives

                                    Nobody remains a virgin, Life screws everyone :sigh:

                                    1 Reply Last reply
                                    0
                                    • T thatraja

                                      Sentenryu wrote:

                                      I don't see the shame on this, this guy just like to write long names :|

                                      :doh: Huh? I don't, read my message again. I don't want the repetitions so I just mentioned the namespace at the top & replaced things.

                                      thatraja

                                      FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI ColdFusion
                                      HTML Marquee & its alternatives

                                      Nobody remains a virgin, Life screws everyone :sigh:

                                      S Offline
                                      S Offline
                                      Sentenryu
                                      wrote on last edited by
                                      #25

                                      I was talking about the original programmer, is that you?

                                      I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                                      T 1 Reply Last reply
                                      0
                                      • L Lost User

                                        Sentenryu wrote:

                                        But it's a matter of taste.

                                        No, it's not. Bloating code is an offence. Three offences, you're out.

                                        Bastard Programmer from Hell :suss:

                                        B Offline
                                        B Offline
                                        BillW33
                                        wrote on last edited by
                                        #26

                                        But, some folk like to bloat their code. ;) ;) I agree, there is no good reason to do this, but it is not as bad as wacky, buggy code.

                                        Just because the code works, it doesn't mean that it is good code.

                                        L 1 Reply Last reply
                                        0
                                        • B BillW33

                                          But, some folk like to bloat their code. ;) ;) I agree, there is no good reason to do this, but it is not as bad as wacky, buggy code.

                                          Just because the code works, it doesn't mean that it is good code.

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #27

                                          CIDev wrote:

                                          I agree, there is no good reason to do this, but it is not as bad as wacky, buggy code.

                                          To quote one of the arguments why it is;

                                          CIDev wrote:

                                          Just because the code works, it doesn't mean that it is good code.

                                          And that's easy to explain; the more symbols you need to convey an idea, the more chances that there's an error in the communication. The more symbols, the more fluff, the more bugs.

                                          Bastard Programmer from Hell :suss:

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups