Hundreds of Ryanair pilots launch court fight over 'withheld' holiday pay
PETER HITCHENS: I have no time for the Tories, but they were absolutely right about Rwanda scheme
Kelly Brook shows off her curves in sexy swimwear as she poses with her shirtless husband Jeremy Parisi and his cousin on holiday
Katherine Ryan, 43, reveals she spent £25K on her facelift and says she wants a 'baby BBL' next as she teases plans for more cosmetic procedures: 'People aren't ready for my glow up'
Alan Brazil reveals he only had 'a couple of weeks to live' before doctors found the 'perfect match' for life-saving liver transplant as talkSPORT legend makes long-awaited return to breakfast show
Can YOU spot the fake? Take the test to see if you can distinguish between real and AI-generated stories - as research reveals people prefer those written by robots
Nearly 1,000 homes could be added to major housing plan across Essex area
Trump's golf rival reveals new details about president's latest 'win' after he declared huge victory in New Jersey club championship
Princess Eugenie and husband Jack Brooksbank welcome baby girl in Portugal: King and Queen say they are 'delighted' to announce newest royal's birth
Popular square outside the late Queen's favourite hotel is overrun by 'aggressive' rough sleepers who terrorise locals and tourists
Afghan accused of killing Brit and hiding her in a suitcase 'texted her friends pretending to be a jihadist who was confessing to murdering her because she was a Christian'
'Nightmare' traffic as 5,600 new homes set to be built around Essex village
Mystery of abandoned 'rainbow baby' who first featured in the Daily Mail 65 years ago is finally solved
Trump reacts after 'heavily armed' man is arrested on his California golf course ahead of his visit as suspect is pictured
Brad Pitt asks court to ORDER Angelina Jolie to turn over financial records after she claimed she put 'career on hold'
New Boeing finally gets going, 15 years after debut
Pesticide warning as study finds link to terrifying motor neurone disease - exposure could raise risk by up to 70%
Blow for Letby families as prosecutors stand by decision against further charges involving six more infants following review
CodeSOD: Connection State
Frederick A sends us a bit of null checking code, and offers us a better solution.
class ConferenceService { /// <summary> /// Checks if conference is active /// </summary> public bool IsCalling() { try { return m_ConnectionService.Core.State.IsWebRTCConnected; } catch { return false; } } }This is for a web conferencing tool, which uses WebRTC to set up connections between clients in the chat. This function checks if the chat is active by checking a IsWebRTCConnected flag. But as you can see in this code, that flag is on a long chain of objects, some of which may not exist when this function is called. Thus, we wrap the whole thing up in a try/catch. If anything throws an exception, we know we can just return false. It's probably fine.
The obvious and easy fix, which Frederick proposes, is to use the C# coalescing operator: ?. m_ConnectionService?.Core?.State?.IsWebRTCConnected ?? false would solve this problem just fine.
That said, I wouldn't say that's a true fix. We're talking about a state machine here, though admittedly with two states under discussion (connected/disconnected), though there are probably more not being checked here. This information should be managed via a state machine, not via boolean flags stuffed deep in an object chain. The fix isn't a WTF, but it definitely hints at a better way to manage all of this. Now, my solution likely requires a lot more modification and code changes than what we have here, so I'm not suggesting anyone go off and rewrite this from scratch just to have a cleaner way of managing state. But folks definitely should think more carefully about how they manage state.
.comment { border: none; }