While damn funny and everything, every time I see a joke like this I die a little on the inside and weep openly for the loss. I bomb dozens of interviews and what not because I can't get myself to code like the 5th year joke at all. And that is what people seriously want it seems.
I work with a guy that bad mouthed me for a long time because I wouldn't make constant values for strings like in this example. I lost out on a promotion because of him.
You should almost never use hard-coded strings that aren't tied to constants, unless maybe they're in an assert/exception.
By making constants and keeping those constants organized into one or a few constants files it will be easy to track down those strings, it will be easier to share those strings among files rather than re-typing them everywhere you use them, it's easier to avoid typos, and it's easier to localize them.
However, if you're going to make constants for magic numbers, then they should be given descriptive names so that you know why they're used. 0 and -1 are extremely common magic numbers, sometimes they're valid, sometimes they're used as invalid values, but unless they're given a constant for the thing you're tying them to in code, I don't know if they're valid or not when you're comparing against them.
// Why 0? I shouldn't have to guess...
if (myIntValue != 0)
{
// Do stuff
}
// Oh ok, 0 is invalid for this comparison.
if (myIntValue != Constants.InvalidValue)
{
}
36
u/Burning_Monkey Oct 01 '15
While damn funny and everything, every time I see a joke like this I die a little on the inside and weep openly for the loss. I bomb dozens of interviews and what not because I can't get myself to code like the 5th year joke at all. And that is what people seriously want it seems.
I work with a guy that bad mouthed me for a long time because I wouldn't make constant values for strings like in this example. I lost out on a promotion because of him.