- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Self modifying source code.. been there, done that, moved to more sane ways of thinking. Also frist.
Admin
Self modifying code is fine as a learning exercise. But for anybody to submit it as part of an operational piece of production code should be a sacking offence. No notice, no warning, just a simple "Get out. Now."
Oy vey.
Admin
The ->[] to access array elements should just be []. The foreach should be 0..$#lines because that gives you exactly what you want and is simpler. The self-modifying thing is just ridiculous, though.
Admin
Not good enough for a wtf, should have modified the code from the same file for that.
Admin
$lines is an arrayref, not an array, so the way the code is written is necessary. The only clear improvement is to change @{$lines} - 1 to $#{$lines}
Admin
Gah!
Ok, I may not be the best to comment on this as I do a lot of Perl coding, but evalling anything user based is just plain wrong and a sceurity hole. Sometimes you have to allow it though (and I have made software where it was possible to allow, but the default has always been to disallow it and the place where it could be enabled always included a huge warning about the issues with enabeling it). But doing regexps on something user-supplied and then evalling it afterwards, that's just like running amok with a hammer in a land mine storage depot....
Admin
...drunk, blindfolded, in the snow, uphill both ways!
Admin
Actually, that explains a lot.
Admin
Now I have a bruise on my forehead from hitting the desk. Good start to the week.
Admin
This is a good one :)
I normally have some 'I once did something similar ...' (even if I was just messing around or I was young and didn't know better), but self-modifying code in production? That is a quality WTF.
Admin
I have to applaud, because normally on these there's a 'well, that's not necessarily a wtf because if the moon is blue and you're being forced to use this Java framework then this is not a terrible hack'. ButI can't think of any situation outside of assembly language on terribly constrained systems (been there, done it) where self-modifying the code (with regexps, even) could be seen as better in any way than just adding a command line parameter or function parameter.
Admin
He's doing it on his own single specific script, not arbitrary scripts, so it's not that giant a security hole in this one case.
But since they're both his own scripts, there's also no excuse for not just doing it properly.
Admin
Works just fine until Bobby Tables gets his CV scanned.
Admin
I know he is doing it on his own script, but he (or the boor guy taking over) has to remember that he can not just add lines to the script without having to consider what those regexex will do the script afterwards. And speaking from experience, going back to something you did a few yers ago to add new functionality or similar can take a while to get in to what the code did in the first place, and then remembering what it will do after a regex replace will likely not be first on the list of things you remember (especially since it mentions that he never wrote any meaningful comments).
Admin
So is the first asterisk meant to be a regex pun, or did someone forget to write the intended footnote?
Admin
He had the inkling to write DRY code, but went about it in the worst possible way.
Admin
I have a feeling that the articles are formatted using (ugh) Markdown, and the asterisk was supposed to be un-bold, but the initial bold character was mis-typed as whatever causes italics. At least there was an extra un-italics in there.
Or maybe Remy ran the article through another Dennis script.
Admin
I submitted this. And I'm sad to report that this is probably the least of his transgressions - I've got plenty more content I'm gonna submit. Stay tuned for regex crimes against humanity
Admin
The arrows are because it's a reference rather than a list
Admin
OP here. Correction, he is doing this on 152 separate scripts. Biggest commit of my life
Admin
Ha I'm sure it's the former. Goes to show these guys don't proofread their shizzle.
Admin
If I'm honest mate I don't think he could even read. He had those massive binocular glasses. Absolute Dilbert
Admin
Gah, so not only do you have to consider what THIS script does, but also think about what other script may or may not do to it later on with regexes and what the script could then do after a failed 'conversion'....
Truely a monumental regex WTF!
I mean even thinking about doing a regex replace on a program/script gives me shivers, but doing it on 100+ scripts... whimper
Admin
Honestly the "framework" as it was so dubbed was essentially one big Rube Goldberg machine that "might" spit out some XML at the end
Admin
Nitpick... but
Skips lines if they don't contain... not if they contain. :)
Admin
He LOVED doing that. Every condition was backwards. He abused the 'unless' keyword. Spent many hours trying to unburst my brain and write them sensibly.
He abused ternaries too. I once found one 5 layers deep. I don't know how I'm still alive.