Short version
Don’t overload a Boolean with three meanings (true = worked, false = tried-and-failed, null = never tried).
Either
- Replace the Booleans with a small enum/ADT that has the three states explicitly, or
- Keep two pieces of information: “was it attempted?” and, if so, “did it succeed?”
Both approaches remove the mental gymnastics (“is null good or bad again?”) and make the code self-documenting.
─────────────────────────────────────────────────────────────
Why the current design bites
─────────────────────────────────────────────────────────────
• A Boolean is, by definition, two-valued. The moment you add null you created a tri-state without telling the compiler.
• Everybody reading the code must remember the hidden semantic: null = “never attempted”.
• Static analysers and IDEs can’t help you because “nullable Boolean” conveys no intent.
• You will inevitably write bugs (“I compared with == true but forgot about null”).
─────────────────────────────────────────────────────────────
Option 1 – one status field (recommended)
─────────────────────────────────────────────────────────────
Model the pipeline as a finite-state machine. One value tells the whole story:
public enum PipelineStatus
{
Running,
Committed, // succeeded and commit succeeded
RollbackSucceeded, // init failed but rollback ok
CommitFailed, // succeeded but commit failed, rollback attempted
RollbackFailed // init failed and rollback failed
}
You now need exactly one property:
public PipelineStatus Status { get; private set; }
Usage:
switch (pipeline.Status)
{
case PipelineStatus.Committed:
...
case PipelineStatus.CommitFailed:
...
}
• No null checks
• State space is explicit
• Impossible to represent an illegal combination (e.g. “commit true while rollback true”).
─────────────────────────────────────────────────────────────
Option 2 – two explicit fields
─────────────────────────────────────────────────────────────
If you really want two dimensions (“did I try?” + “did it succeed?”) keep them separate:
public enum AttemptResult { NotAttempted, Succeeded, Failed }
public AttemptResult CommitResult { get; private set; } = AttemptResult.NotAttempted;
public AttemptResult RollbackResult { get; private set; } = AttemptResult.NotAttempted;
This is mechanically close to what you have, but replaces “null” with “NotAttempted”, a value the compiler understands.
─────────────────────────────────────────────────────────────
“But I only want Booleans!”
─────────────────────────────────────────────────────────────
Then you need two Booleans per action:
commitAttempted : bool
commitSucceeded : bool (only meaningful if attempted)
rollbackAttempted : bool
rollbackSucceeded : bool
That works, but you now have four flags to keep consistent instead of one enum value. For most cases the enum is simpler.
─────────────────────────────────────────────────────────────
Migration tip
─────────────────────────────────────────────────────────────
- Introduce the new enum property alongside the old Booleans.
- Populate it wherever the old flags are written.
- Gradually update consumers to read the enum, then delete the old fields.
─────────────────────────────────────────────────────────────
Take-away
─────────────────────────────────────────────────────────────
• Avoid “nullable Booleans with magic meaning”.
• Make the illegal states unrepresentable—an enum or sealed class does that perfectly.
• Future readers (including you) will thank you.