Take the 2-minute tour ×

Many people believe Hungarian notation is bad. How then do you name a variables that represent the same value casted to different types?

I've got a variable called value, that might be a string, or a decimal. What would you call the different formats? strValue, decValue? valueAsString?

share|improve this question
I don't worry about it, I just use the most apt name for it, and cast it as needed. I guess if it really mattered I'd make an object out of it and use value.asString() or value.asInt(). –  jcomeau_ictx Nov 12 '10 at 3:15
It's actually a little more than just a cast...more like parsing. It doesn't have a big enough scope to warrant its own class though. –  Mark Nov 12 '10 at 3:49
Arguably, if there is custom parsing etc, that probably makes a good case for a simple struct to encapsulate the parsing logic etc; I am thinking along the lines of int.Parse. –  Chris Baxter Nov 12 '10 at 4:08

1 Answer 1

up vote 3 down vote accepted

I think it would largely depend on the context. For instance if the string value was named age, and the decimal was the parsed value then perhaps parsedAge or something along those lines. Really it comes down to what makes sense given what you are doing and the lifetime of that variable. If it only exists long enough to actually collect and parse the value, then I would give the better name to the parsed variable or worry less about the naming of the intermediary.

If you actually need to hold on to both values, then I might consider creating a struct or some similar data structure that represents the various forms for that data value to prevents the need to shift between string and decimal formats etc.

share|improve this answer
I'm parsing the value up front, and then later on depending on which branch it takes, it might use either value, so I'm holding on to both. Both values would be considered "parsed" so naming like that doesn't really make sense. –  Mark Nov 12 '10 at 3:48
@Mark - Makes sense, does the branch taken at all depend on the "parsed" values? If not, can you push the parsing down to where it is needed? Either that, or the struct may be the way to go. –  Chris Baxter Nov 12 '10 at 3:57
Actually there's a switch... about a 3rd of them need one value, a 3rd need another, some need both... can't really push it down :) –  Mark Nov 12 '10 at 6:22

Your Answer


