Comment Switching
-
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)
-
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)
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
-
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
-
Look at MSDN for the full list of C# Preprocessor Directives[^]
Yes..?
-- Kein Mitleid Für Die Mehrheit
-
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
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)
-
Yes..?
-- Kein Mitleid Für Die Mehrheit
-
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)
-
It would be even cleverer if you used
string.Empty
instead of""
. :)"You get that on the big jobs."
-
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)
-
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
Oh, ok!
-- Kein Mitleid Für Die Mehrheit
-
way too much typing
My opinions are right, and yours are wrong! (or at least that is my opinion)
Are you using notepad to write code? OK, two key-presses vs. four is a win, but certainly not a lot of typing.
-
way too much typing
My opinions are right, and yours are wrong! (or at least that is my opinion)
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.
-
It would be even cleverer if you used
string.Empty
instead of""
. :)"You get that on the big jobs."
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.
-
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.
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."
-
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."
Lol sorry, I actually misread and thought it was
public const string MyString = string.Empty
Sorry about that.
-
Lol sorry, I actually misread and thought it was
public const string MyString = string.Empty
Sorry about that.
-
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."
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.
-
way too much typing
My opinions are right, and yours are wrong! (or at least that is my opinion)
-
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."
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.
-
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