Nearly 4,000 cyber-flashing crimes recorded in six months – Essex among highest
Ex-West Ham footballer Andy Carroll avoids driving ban after filming Essex protests
Essex man running 74 ultramarathons in 74 days will break Guinness World Record
Jeff Brazier's son reveals he attempted to end it all in newest TikTok
Essex Police officer dismissed for gross misconduct for inappropriate behaviour
Regular semi-detached home goes on sale for £320k - but it houses a remarkable secret inside
Police appeal as Essex man missing for 7 days-have you seen him?
I'm a Celeb fame Stacey Solomon shares new life update with fans
Fundraiser started for boy, 11, who died after GP told him he had 'just a virus'
Major disruption on all Greater Anglia trains to and from London Stansted Airport
Oasis support artist announced as headliner for Summer Series gig
Listed: Best 'cheap eats' Essex restaurants named among top in the country
Successful indie-pop band announced as next Essex Summer Series headliner
£110 million 'giga mansion' in Belgrave Square will become one of London's most expensive homes - with global billionaires targeted as most likely buyers
CodeSOD: Copied Homework
Part of the "fun" of JavaScript is dealing with code which comes from before sensible features existed. For example, if you wanted to clone an object in JavaScript, circa 2013, that was a wheel you needed to invent for yourself, as this StackOverflow thread highlights.
There are now better options, and you'd think that people would use them. However, the only thing more "fun" than dealing with code that hasn't caught up with the times is dealing with developers who haven't, and still insist on writing their own versions of standard methods.
const objectReplace = (oldObject, newObject) => { let keys = Object.keys(newObject) try { for (let key of keys) { oldObject[key] = newObject[key] } } catch (err) { console.log(err, oldObject) } return oldObject }It's worth noting that Object.entries returns an array containing both the keys and values, which would be a more sensible for this operation, but then again, if we're talking about using correct functions, Object.assign would replace this function.
There's no need to handle errors here, as nothing about this assignment should throw an exception.
The thing that really irks me about this though is that it pretends to be functional (in the programming idiom sense) by returning the newly modified value, but it's also just changing that value in place because it's a reference. So it has side effects, in a technical sense (changing the value of its input parameters) while pretending not to. Now, I probably shouldn't get too hung up on that, because that's also exactly how Object.assign behaves, but dammit, I'm going to be bothered by it anyway. If you're going to reinvent the wheel, either make one that's substantially worse, or fix the problems with the existing wheel.
In any case, the real WTF here is that this function is buried deep in a 15,000 line file, written by an offshore contract team, and there are at least 5 other versions of this function, all with slightly different names, but all basically doing the same thing, because everyone on the team is just copy/pasting until they get enough code to submit a pull request.
Our submitter wonders, "Is there a way to train an AI to not let people type this?"
No, there isn't. You can try rolling that boulder up a hill, but it'll always roll right back down. Always and forever, people are going to write bad code.