Toddler goes missing from Sydney childcare centre for HOURS after grandfather's grave error
CodeSOD: Adding to the Argument
David G saw a pull request with a surprisingly long thread of comments on it. What was weirder was that the associated ticket was all about adding a single parameter to an existing method. What could be generating that much discussion?
How could adding an argument add to an argument?
registerFooWrapper: function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7, }); }); }This is the original version of the JavaScript function. The parameter names have been anonymized. That aside, this still isn't very good. Seven parameters is likely too many, and based on what I see in setting the context, there is an object type that holds them all, so maybe we should be passing the object around in the first place? Still, this isn't a WTF by any stretch, and since it's already deployed code, changing the interface significantly is a bad idea- maybe just adding a parameter is the right choice here. So what generated so much discussion?
This revision:
registerFooWrapper: function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, notArg8) { if (notArg8 === true) { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7, arg8: !notArg8, }); }); } else { bar.when('bar-event', function(context) { context.foo({ arg1: arg1, arg2: arg2, arg3: arg3, arg4: arg4, arg5: arg5, arg6: arg6, arg7: arg7 }); }); } }Okay, so if notArg8 is true, we pass false to the context. If it's any other value, we don't past arg8 at all. I do not understand what I'm looking at here. If the goal is to ensure that arg8 is either true or not set, there are clearer ways to express that idea. But also, the goal of the ticket was not to do that- it was simply to add another parameter, which means you could drop the condition entirely and just add the parameter. context was already receiving arg8 as undefined, so it could clearly handle an undefined value.
David made some comments on the pull request, but the original developer just ended up going radio silent on it. One of the juniors on David's team approved it, for some reason, but nobody ever actually hit merge. Instead, a different developer simply made a version that took arg8 as a parameter, passed it down to context, and called it a day. It worked, the tests passed, and everyone was happy.
Well, except the original developer, but again, who knows what they were trying to do?
Moment suspect flees undercover cops during car stop arrest attempt in North London
Massive trove of Epstein files released by GOP includes infamous missing minute from jailhouse video
Victoria's police chief SNAPS at reporter's question about why 450 cops still haven't found wanted fugitive Dezi Freeman
Dwarfed by delivery Britain: Anger as 'monstrous' 60ft tall warehouses are built metres from family homes 'like a cruise ship in our back garden'
The secret role the Duke of Kent played in the run up to World War II revealed: How the patriotic royal directly violated Neville Chamberlain's wishes acting as a rogue secret agent
Kentucky cheerleader, 21, appears glammed up in court to face charges for 'hiding dead baby in trash bag'
New buses to serve Essex village in one-year trial to 'boost passenger numbers'
Internet mapping and research outfit Censys reveals state-based abuse, harassment
Censys Inc, vendor of the popular Censys internet-mapping tool, has revealed that state-based actors are trying to abuse its services by hiding behind academic researchers.…
Locals fear new nursery will cause 'mayhem' on busy Essex road
Disgraced Essex teacher banned after 'woman in underwear' shown on screen to pupils
Kim Kardashian says she 'doesn't believe' in giving kids homework
Cardi B is CLEARED in civil assault trial after epic MELTDOWN outside court over pregnancy rumor
The surprisingly easy way to beat travel sickness, according to scientists
Planning appeal for Essex farm dismissed over noise impact concerns
Plans for 140 new homes in 'struggling 'village will put locals at 'further risk'
Jennifer Aniston, 56, reveals what procedures she has done to her face... a year after she was seen outside plastic surgeon's office
They fantasized about a 'fortress of Christianity'. Now US expats in Russia reveal harrowing details of their new lives... and what they're forced to do
India hails 'first' home-grown chip as a milestone despite very modest specs
India’s government yesterday celebrated an “important milestone” in the development of its semiconductor industry, and therefore the nation’s ambition to become a global contender, but the celebrations seem premature because the chip that was the star of the show is nothing special.…