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. Clever Code
  4. Comment Switching

Comment Switching

Scheduled Pinned Locked Moved Clever Code
debuggingdiscussion
20 Posts 10 Posters 97 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.
  • J Jorgen Sigvardsson

    How about

    public static string MyString =
    #if USE_MY_SPECIAL_DEBUG_VALUE
    @"DEBUG VALUE"
    #else
    ""
    #endif
    ;

    Surely, this must be a lot more maintainable than a very cryptic looking comment that's going to make your successors wonder WTF?

    -- Kein Mitleid Für Die Mehrheit

    M Offline
    M Offline
    musefan
    wrote on last edited by
    #5

    Firstly, class files are not limited to a single line of comment you know. I have extra comments explaining the need to use the debug value in some instances so successors can work it out fairly easy. Secondly, there is nothing clever or interesting about your code, it is a pretty standard if/else. And yes, I know you can say the same about mine, but I think it is a bit more out of the box thinking which is why I posted it. Of course, this forum is really only for people to mock other people anyway

    My opinions are right, and yours are wrong! (or at least that is my opinion)

    1 Reply Last reply
    0
    • J Jorgen Sigvardsson

      Yes..?

      -- Kein Mitleid Für Die Mehrheit

      R Offline
      R Offline
      Reiss
      wrote on last edited by
      #6

      You have pointed the user at the #if preprocessor (getting my 5), so I thought it might be useful to show the full listing - especially the #define and #undefine preprocessors as theses are commonly used with the #if

      J 1 Reply Last reply
      0
      • M musefan

        I have a static string which I am constantly switch to a known value for debugging. But now I have come up with something that saves me 3 key strokes!!! consider...

        public static string MyString = "";//@"DEBUG VALUE";

        ...I was constantly deleting

        "";//

        and re-adding for each toggle. Now I have changed to this...

        public static string MyString = "";//*/@"DEBUG VALUE";

        ...now I just need to add/remove

        /*

        each time to toggle the value...

        public static string MyString = /*"";//*/@"DEBUG VALUE";

        result! :laugh: ...and I don't want to hear about your #DEBUG comments

        My opinions are right, and yours are wrong! (or at least that is my opinion)

        R Offline
        R Offline
        RobCroll
        wrote on last edited by
        #7

        It would be even cleverer if you used string.Empty instead of "". :)

        "You get that on the big jobs."

        M G 2 Replies Last reply
        0
        • R RobCroll

          It would be even cleverer if you used string.Empty instead of "". :)

          "You get that on the big jobs."

          M Offline
          M Offline
          musefan
          wrote on last edited by
          #8

          way too much typing

          My opinions are right, and yours are wrong! (or at least that is my opinion)

          B F P 3 Replies Last reply
          0
          • M musefan

            I have a static string which I am constantly switch to a known value for debugging. But now I have come up with something that saves me 3 key strokes!!! consider...

            public static string MyString = "";//@"DEBUG VALUE";

            ...I was constantly deleting

            "";//

            and re-adding for each toggle. Now I have changed to this...

            public static string MyString = "";//*/@"DEBUG VALUE";

            ...now I just need to add/remove

            /*

            each time to toggle the value...

            public static string MyString = /*"";//*/@"DEBUG VALUE";

            result! :laugh: ...and I don't want to hear about your #DEBUG comments

            My opinions are right, and yours are wrong! (or at least that is my opinion)

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

            Nah, you debug it with Windbg and set the variable in the module directly, while its running.

            ============================== Nothing to say.

            1 Reply Last reply
            0
            • R Reiss

              You have pointed the user at the #if preprocessor (getting my 5), so I thought it might be useful to show the full listing - especially the #define and #undefine preprocessors as theses are commonly used with the #if

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #10

              Oh, ok!

              -- Kein Mitleid Für Die Mehrheit

              1 Reply Last reply
              0
              • M musefan

                way too much typing

                My opinions are right, and yours are wrong! (or at least that is my opinion)

                B Offline
                B Offline
                Brady Kelly
                wrote on last edited by
                #11

                Are you using notepad to write code? OK, two key-presses vs. four is a win, but certainly not a lot of typing.

                1 Reply Last reply
                0
                • M musefan

                  way too much typing

                  My opinions are right, and yours are wrong! (or at least that is my opinion)

                  F Offline
                  F Offline
                  fjdiewornncalwe
                  wrote on last edited by
                  #12

                  The proper way is the right way. With intellisense and all the other editor enhancements that make life easier for developers, the "too much typing" excuse doesn't hold water. If you have issues typing, then you need to brush up on that because writing code incorrectly at the outset is just going to make a sustainment developer's job much more difficult.

                  I wasn't, now I am, then I won't be anymore.

                  1 Reply Last reply
                  0
                  • R RobCroll

                    It would be even cleverer if you used string.Empty instead of "". :)

                    "You get that on the big jobs."

                    G Offline
                    G Offline
                    gumi_r msn com
                    wrote on last edited by
                    #13

                    Actually that wouldn't compile I think.

                    string.Empty

                    is readonly so you can't initialize a static variable with it as it could theoretically change during runtime.

                    R 1 Reply Last reply
                    0
                    • G gumi_r msn com

                      Actually that wouldn't compile I think.

                      string.Empty

                      is readonly so you can't initialize a static variable with it as it could theoretically change during runtime.

                      R Offline
                      R Offline
                      RobCroll
                      wrote on last edited by
                      #14

                      You had me worried there for a second. I've done find replace on "" on large projects (millions of lines) and never had any adverse affects, let alone a compile error. public static string MyString = string.Empty; compiles for me.

                      "You get that on the big jobs."

                      G 1 Reply Last reply
                      0
                      • R RobCroll

                        You had me worried there for a second. I've done find replace on "" on large projects (millions of lines) and never had any adverse affects, let alone a compile error. public static string MyString = string.Empty; compiles for me.

                        "You get that on the big jobs."

                        G Offline
                        G Offline
                        gumi_r msn com
                        wrote on last edited by
                        #15

                        Lol sorry, I actually misread and thought it was

                        public const string MyString = string.Empty

                        Sorry about that.

                        R 1 Reply Last reply
                        0
                        • G gumi_r msn com

                          Lol sorry, I actually misread and thought it was

                          public const string MyString = string.Empty

                          Sorry about that.

                          R Offline
                          R Offline
                          RobCroll
                          wrote on last edited by
                          #16

                          Obscure but still worth noting. I guess at the end of the day who would set a const to equal ""?

                          "You get that on the big jobs."

                          L F 2 Replies Last reply
                          0
                          • R RobCroll

                            Obscure but still worth noting. I guess at the end of the day who would set a const to equal ""?

                            "You get that on the big jobs."

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

                            Actually its a constant equal to string.Empty... which ahh is already what you should be using. Kinda like when you see

                            const bool TRUE = true;

                            Note: I have never actually seen this except in code horrors responding jokes.

                            Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

                            1 Reply Last reply
                            0
                            • M musefan

                              way too much typing

                              My opinions are right, and yours are wrong! (or at least that is my opinion)

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

                              String.Empty runs faster.

                              1 Reply Last reply
                              0
                              • R RobCroll

                                Obscure but still worth noting. I guess at the end of the day who would set a const to equal ""?

                                "You get that on the big jobs."

                                F Offline
                                F Offline
                                fjdiewornncalwe
                                wrote on last edited by
                                #19

                                RobCroll wrote:

                                I guess at the end of the day who would set a const to equal ""?

                                Have you been in the Q&A recently? :)

                                I wasn't, now I am, then I won't be anymore.

                                1 Reply Last reply
                                0
                                • J Jorgen Sigvardsson

                                  How about

                                  public static string MyString =
                                  #if USE_MY_SPECIAL_DEBUG_VALUE
                                  @"DEBUG VALUE"
                                  #else
                                  ""
                                  #endif
                                  ;

                                  Surely, this must be a lot more maintainable than a very cryptic looking comment that's going to make your successors wonder WTF?

                                  -- Kein Mitleid Für Die Mehrheit

                                  K Offline
                                  K Offline
                                  Ken Booth
                                  wrote on last edited by
                                  #20

                                  I agree - not only more readable, but the line

                                  #define USE_MY_SPECIAL_DEBUG_VALUE

                                  can be commented or uncommented with one mouse click - no keystrokes required!

                                  -- Regards, Ken I AM

                                  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