CodeSOD: Stripped of Magic
A Representative Line is a short snippet that makes you think, "wow, I'd hate to see the rest of the code." A CodeSOD is a longer snippet, which also frequently makes you think, "wow, I'd hate to see the rest of the code," but also is bad in ways that require you to look at the relationship between the lines in the code.
I bring that up, because today's code sample is a long section, but really, it's just a collection of representative lines. Each line in this just makes me die a little on the inside.
Belda found this:
## helper functions function stripmagic($x) { return get_magic_quotes_gpc() ? stripslashes($x) : $x; } function pre_r(&$x) { return '<pre>'.PHSC(print_r($x, true)).'</pre>'; } function PSS($x) { return str_replace('\\"','"',$x); } function PVS($x) { return preg_replace("/\n[^\\S\n]*(?=\n)/", "\n<:vspace>", $x); } function PVSE($x) { return PVS(PHSC($x, ENT_NOQUOTES)); } function PZZ($x,$y='') { return ''; } function PRR($x=NULL) { if ($x || is_null($x)) $GLOBALS['RedoMarkupLine']++; return $x; } function PUE($x) { return preg_replace('/[\\x80-\\xff \'"<>]/e', "'%'.dechex(ord('$0'))", $x); } function SDV(&$v,$x) { if (!isset($v)) $v=$x; } function SDVA(&$var,$val) { foreach($val as $k=>$v) if (!isset($var[$k])) $var[$k]=$v; }This collection of one-line "helper" functions has it all. Cryptic function names. PRR mutates global variables. PZZ just… returns an empty string. I don't know what PHSC does, and I don't want to, but it's called inside of pre_r and PVSE. Which I also don't know what they do. Speaking of PVSE, I note the regex is using backreferences, which is some advanced regex but I still have no idea what it's doing. I could figure it out, but I don't want to. PUE looks like it might be handling some misencoded characters, maybe. SDV is maybe kinda a coalesce function.
Each line is its own representative line. None of this is code I'd want to maintain.
On the flip side, the abbreviated function names, when read in reverse order, are exactly the sounds I made when I read this code: "SDVASDVPUEPRRPZZPVSEPVSPSS".
It's okay, the doctors say I'll make a full recovery.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
The Traitors star Minah breaks her silence on brutal banishment and reveals what she really thinks of her rival Charlotte
The 'ice rink' Essex road residents claim is becoming an accident hotspot
Beijing picking up some of the bill for iPhones sold in China
If you want a cheap iPhone, China’s the place to be right now thanks to a government subsidy scheme that means resellers are discounting the devices to make sure Beijing helps to pick up the bill.…
Aussie actor Guy Pearce and his Game Of Thrones star girlfriend Carice van Houten confirm split after several years together - as actress reveals big secret about their relationship
CNN bloodbath begins with hundreds on the chopping block as network restructures for the Trump era
5 pets at RSPCA Essex who are searching for their forever homes
Walthamstow family awarded £5k after landlord cuts power amid rent dispute
Shopkeeper fined £12k for selling counterfeit cigarettes from 'Candy Land' sweet shop
5 pets at RSPCA Essex who are searching for their forever homes
Number of children hospitalised with eating disorders rockets by more than 500 per cent in a decade, study reveals
Rachel Reeves put Britain's army of more than 100 regulators on notice saying they were getting in the way of growth
Would YOU wear this to your hens? Bride-to-be puts on a VERY daring display in a barely-there racy party dress - after dividing fans with her wild bachelorette outfits
Government agency is caught deploying sneaky tactic to get around Trump's anti-woke purge
Benedict Cumberbatch reveals he was KIDNAPPED while on location in South Africa: 'It made me impatient to live a life less ordinary'
Fans are all saying the same thing as Meg Ryan and Billy Crystal are pictured in When Harry Met Sally Reunion
Half the country will end up in A&E unless the NHS is reformed, England's top doctor warns
DHS Terminates All Its Advisory Committees, Ending Its Investigation Into Chinese Telecom Hack
Read more of this story at Slashdot.