The fashion signs you're getting old: Stylist reveals the wardrobe items that are officially ageing you
Will the King snub his nieces Beatrice and Eugenie over Epstein links? CHARLOTTE GRIFFITHS reveals his dilemma in the Palace Confidential
Don't waste your money, here's how to get barista-standard coffee and the ultimate cafe set up at home - all the trendy coffee snobs would approve
Has skiing become more dangerous? As avalanches hit resorts all over the world, experts reveal what's really going on
South Korea's ex-president avoids death penalty but is jailed for life for leading an insurrection by declaring martial law in 2024
Cat Deeley's khaki knitted dress looks straight out of Kate Middleton's wardrobe - and it's still in stock
Elderly woman fined £300 by 'ruthless' council after leaving charity donation bag outside her home
Trump 'identifies timeline for strike on Iran' as world's largest aircraft carrier heads to the Middle East
Mark Zuckerberg's awkward response to scathing question from lawyer accusing him of being 'robotic' during tense courtroom duel
Daughter of trans hockey shooter says he had 'vendetta against his family' and was ostracized by his six kids BEFORE he transitioned
Scottish lesbian group criticise Olivia Colman for describing herself as a 'gay man' in her marriage to Ed Sinclair and claiming she 'feels nonbinary' saying 'her words are deeply painful and diminish our struggle'
Amanda Holden, 55, showcases her age-defying figure in bright bikinis as she rings in her birthday with stay at £1,300-per-night luxury Dubai hotel
US assembles the most aerial firepower since Iraq War as Trump prepares to strike Iran 'in just DAYS'... and president is 'choosing between two devastating options of attack'
Kylie Jenner and Timothee Chalamet enjoy PDA-packed pizza dinner as they shut down restaurant for low-key date
Police fear rapist who lured woman to hotel on promise of work assisting injured sportsman before assaulting her may have attacked others
Eon Next is offering the cheapest fixed energy deal from a major supplier - should you sign up?
Insurance claims for floods and subsidence are rising as Britain's weather causes more damage
Pubs will be able to stay open until 2am during the World Cup if home nations get to the knockout stage
CodeSOD: Terned Backwards
Antonio has an acquaintance has been seeking career advancement by proactively hunting down and fixing bugs. For example, in one project they were working on, there was a bug where it would incorrectly use MiB for storage sizes instead of MB, and vice-versa.
We can set aside conspiracy theories about HDD and RAM manufacturers lying to us about sizes by using MiB in marketing. It isn't relevant, and besides, its not like anyone can afford RAM anymore, with crazy datacenter buildouts. Regardless, which size to use, the base 1024 or base 1000, was configurable by the user, so obviously there was a bug handling that flag. Said acquaintance dug through, and found this:
const baseValue = useSI ? 1000 : 1024;I know I have a "reputation" when it comes to hating ternaries, but this is a perfectly fine block of code. It is also correct: if you're using SI notation, you should do base 1000.
Now, given that this code is correct, you or I might say, "Well, I guess that isn't the bug, it must be somewhere else." Not this intrepid developer, who decided that they could fix it.
// const baseValue = useSI ? 1000 : 1024; baseValue = 1024 if (useSI === false) { baseValue = 1000; } if (useSI === true) { baseValue = 1024; }It's rather amazing to see a single, correct line, replaced with ten incorrect lines, and I'm counting commenting out the correct line as one of them.
First, this doesn't correctly declare baseValue, which JavaScript is pretty forgiving about, but it also discards constness. Of course, you have to discard constness now that you've gotten rid of the ternary.
Then, our if statement compares a boolean value against a boolean literal, instead of simply if(!useSI). We don't use an else, despite an else being absolutely correct. Or actually, since we defaulted baseValue, we don't even need an else!
But of course, all of that is just glitter on a child's hand-made holiday card. The glue holding it all together is that this code just flips the logic. If we're not using SI, we set baseValue to 1000, and if we are using SI, we set it to 1024. This is wrong. This is the opposite of what the code says we should do, what words mean, and how units work.