I'd like to test if an id was not yet known or, if it is known, if the associated value has changed. I'm currently using code similar to this, but it is hard to understand for those not familiar with the pattern. Can you think of a way to make it more readable while keeping it short in LOC?
string id;
string actual;
string stored;
if (!someDictionary.TryGetValue (id, out stored) || stored != actual) {
// id not known yet or associated value changed.
}
out
parameter. "…get used to it?" It isn't that devs are "confused", per se. Even a veteran programmer who reads left-to-right has to bounce back, forth, and up just to read this, and juggle several elements in the mind while so doing. This isn't a hard task, but it isn't natural, either. This is somewhat procedural code and introduces opportunities for repetition and error. Readability is a legitimate concern andTryGetValue
with abool
result is semantically weak. – Stillage