Lucky Essex resident wins £100k prize as October Premium Bond winners revealed
Princess Anne, 75, makes top secret visit to Ukraine - weeks after Prince Harry made surprise trip to the country
Ronnie O'Sullivan reveals he has QUIT the UK for Dubai because his new wife gave him an ultimatum about living in Sheffield after they rekindled romance
The Surrey hamlet where 'invading' travellers 'outnumber' homeowners who are being forced to sell up and move away...or 'go to war' over 'illegal' land-grabbers
Kate Moss hides behind dark glasses and clings to her bodyguard as she enjoys another night out in Paris during Fashion Week
Roast didn't come with the unlimited Yorkshire puddings advertised. Can I demand a refund? DEAN DUNHAM replies
Away from Oktoberfest, Munich's museums also serve science on tap
Geek's Guide It's September and the German city of Munich is celebrating Oktoberfest. But away from the beer tents, schnitzel, and lederhosen lies a set of museums worth visiting for the price of a few beers.…
Prince Alexander of Serbia, 43, ties the knot for a second time as he weds glamorous dentist Dr Vesna Jelić in lavish ceremony attended by senior royals
Now David Lammy is forced to apologise for hysterically accusing Nigel Farage of 'flirting with the Hitler Youth' in new low for Labour's 'racism' row with Reform
Family rift over Educating Yorkshire headteacher, 53, and his girlfriend, 25: Daughters he shares with ex-wife have 'struggled' with relationship that's seen him branded a 'paedophile and groomer'
'Buy one, get one free' junk food deals banned from TODAY
Kim Cattrall, 69, brings some Sex And The City glamour to Debenhams as she fronts glitzy new campaign for high street brand
Mysterious death of the boy who 'did not exist': Daniel, 3, vanished from official records and his grandparents had no idea he'd even been born. Now, his parents claim he died in his sleep in 2021 and they buried him in a panic
Independent UK Bookshops To Begin Selling eBooks
Read more of this story at Slashdot.
LIVE: A12 partially blocked between Kelvedon north and south after collision
Grand Designs host Kevin McCloud admits he has 'mixed feelings' after show's 'saddest ever' home finally sold following 10-year saga that left viewers in floods of tears
George Clooney insists he lives 'normal' life... despite having multiple homes and $500 million net worth
CodeSOD: Property Flippers
Kleyguerth was having a hard time tracking down a bug. A _hasPicked flag was "magically" toggling itself to on. It was a bug introduced in a recent commit, but the commit in question was thousands of lines, and had the helpful comment "Fixed some stuff during the tests".
In several places, the TypeScript code checks a property like so:
if (!this.checkAndPick) { // do stuff }Now, TypeScript, being a Microsoft language, allows properties to be just, well, properties, or it allows them to be functions with getters and setters.
You see where this is going. Once upon a time was a property that just checked another, private property, and returned its value, like so:
private get checkAndPick() { return this._hasPicked; }Sane, reasonable choice. I have questions about why a private getter exists, but I'm not here to pick nits.
As we progress, someone changed it to this:
private get checkAndPick() { return this._hasPicked || (this._hasPicked = true); }This forces the value to true, and returns true. This always returns true. I don't like it, because using a property accessor to mutate things is bad, but at least the property name is clear- checkAndPick tells us that an item is being picked. But what's the point of the check?
Still, this version worked as people expected it to. It took our fixer to take it to the next level:
private get checkAndPick() { return this._hasPicked || !(this._hasPicked = true); }This flips _hasPicked to true if it's not already true- but if it does, returs false. The badness of this code is rooted in the badness of the previous version, because a property should never be used this way. And while this made our fixer's tests turn green, it broke everything for everyone else.
Also: do not, do not use property accessors to mutate state. Only setters should mutate state, and even then, they should only set a field based on their input. Complicated logic does not belong in properties. Or, as this case shows, even simple logic doesn't, if that simple logic is also stupid.
Blockchain just became an utterly mainstream part of the global financial system
Blockchains are still synonymous with the wild world of cryptocurrencies, but on Monday, 30 banks and SWIFT – the world’s most important cross-border payment service – made them an utterly mainstream part of the global financial system.…