In a recent CodeSOD installment on The Daily WTF, Remy Porter presents a snippet submitted by reader Frederick A from a web conferencing tool that uses WebRTC to connect chat clients.

The method in question, IsCalling on a ConferenceService class, is documented as checking whether a conference is active. Its entire logic consists of returning m_ConnectionService.Core.State.IsWebRTCConnected wrapped in a try block, with a bare catch that swallows any exception and returns false. The reasoning: several objects in that chain may not exist at call time, so any thrown NullReferenceException conveniently signals "not connected."

Frederick proposes the idiomatic C# fix: m_ConnectionService?.Core?.State?.IsWebRTCConnected ?? false, using the null-conditional and null-coalescing operators instead of exception-driven control flow.

Porter accepts that fix but notes it is not a true solution. Connection state is really a state machine — connected, disconnected, and likely further states going unchecked — and burying it as a boolean flag deep inside an object graph is the underlying smell. He stops short of recommending a rewrite, but urges developers to think more deliberately about how they model state.