Liam Payne given heartbreaking tribute at the start of new Netflix series Building The Band which was filmed before his tragic death
Proton bashes Apple and joins antitrust suit that seeks to throw the App Store wide open
Secure comms biz Proton has joined a lawsuit that alleges Apple’s anticompetitive ways are harming developers, consumers, and privacy.…
CodeSOD: It's Not Wrong to Say We're Equal
Aaron was debugging some C# code, and while this wasn't the source of the bug, it annoyed him enough to send it to us.
protected override int DoCompare(Item item1, Item item2) { try { DateTime thisDate = ((DateField)item1.Fields["Create Date"]).DateTime; DateTime thatDate = ((DateField)item2.Fields["Create Date"]).DateTime; return thatDate.CompareTo(thisDate); } catch (Exception) { return 0; // Sorry, ran out of budget! } }Not to be the pedantic code reviewer, but the name of this function is terrible. Also, DoCompare clearly should be static, but this is just pedantry.
Now, there's a lot of implied WTFs hidden in the Item class. They're tracking fields in a dictionary, or maybe a ResultSet, but I don't think it's a ResultSet because they're converting it to a DateField object, which I believe to be a custom type. I don't know what all is in that class, but the whole thing looks like a mess and I suspect that there are huge WTFs under that.
But we're not here to look at implied WTFs. We're here to talk about that exception handler.
It's one of those "swallow every error" exception handlers, which is always a "good" start, and it's the extra helpful kind, which returns a value that is likely incorrect and provides no indication that anything failed.
Now, I suspect it's impossible for anything to have failed- as stated, this seems to be some custom objects and I don't think anything is actively talking to a database in this function (but I don't know that!) so the exception handler likely never triggers.
But hoo boy, does the comment tell us a lot about the codebase. "Sorry, ran out of budget!". Bugs are inevitable, but this is arguably the worst way to end up with a bug in your code: because you simply ran out of money and decided to leave it broken. And ironically, I suspect the code would be less broken if you just let the exception propagate up- if nothing else, you'd know that something failed, instead of incorrectly thinking two dates were the same.
.comment { border: none; }The Bezos-Sanchez wedding was a $20 million trash fest… but it's made all the more embarrassing by the A-list couple who've shown them how to REALLY do it
The shocking scandals behind the Monaco throne as Prince Albert and Princess Charlene celebrate their wedding anniversary
Terrifying moment out-of-control lorry hurtles along bridge and smashes into a car sending it flying over the edge - with occupants somehow surviving
Erin Patterson mushroom murder trial LIVE updates: Countdown to verdict as jury continues deliberations today
Natalie Portman's rarely seen son, 13, calls in mom to impress YouTube star
How haggling on car insurance could land you £200 off your renewal quote
Doting mom Serena Williams soaks up the Sardinian sun on luxury yacht with husband Alexis Ohanian and family
China successfully tests hypersonic aircraft, maybe at Mach 12
China’s Northwestern Polytechnical University last week flew a hypersonic craft and claimed the test achieved some world-first feats.…