Cross stitch syntax (kind of urgent)

Yeah, but I also don't like when the 99% case for my boolean is for me to use negation. There's a problem with just treating those guidelines as Gospel truths that can't be broken.

I wouldn't write:

if (didHumanitySayNo)
{
    DontKillEveryone();
}

The whole thing is wonky. It'd be better to have:

if (shouldSaveHumanity)
{
    SaveEveryone();
}

Going back to the case, I feel like unsure reads more cleanly than !sure in this isolated context. But it assumes we also wrote code to get it like:

var dialogResult = MessageBox.Show("Are you sure you have the right name?");

bool isUnsure = dialogResult == DialogResult.No;

if (isUnsure)
{
    name.Ask();
}

// Now we know we have a name.

The larger context shows a clear chain of how we get here. I feel like negative logic only works 1% of the time, but when you're in the rare case you should use what works for it. I'd argue in this case we could get rid of the boolean entirely, but then we're not making the cross-stitch very funny anymore.

That's the other side of the equation: I'm not trying to pass a code review here. I'm trying to help someone craft a gift. But I'd defend this in a PR, as well.

By the way, you shouldn't use triple backticks on reddit. It only works for some clients.

/r/csharp Thread Parent