- 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
This is like the 3rd or 4th instance of a deeply nested replace on this site. It still makes me shiver.
Admin
At least you get a nice big tree when formatted!
Admin
There is a reason why the infamous Darwin Award has "too common" as a disqualifier.
Admin
I wonder whether somebody, being too clever for their own good (how I hate that phrase, even when I use it myself) has built an automatic replace-method writer. Not realising that it's possible to write just one "replace" method and pass it the appropriate parameters, they have set themselves up to write a different replace for each of the situations where they want to do this replacing operation, but a different one according to the needs of the situation.
Their automatic replace-method generation tool does something like: "Enter the charicter you want to repalce.(gohome for fin ish) "Enter the charicter you want ot replaced with" and it then goes round and round till you enter gohome. At that point it then generates your automatic Replace generator.
Note that I have failthfully retained the various typos and instances of diskexya.
Admin
I think the author of that code utterly disliked regular expressions. Maybe it was blakey — he dislikes regular expressions too.
Admin
Too well-indented and professionally laid out for blakey. He would have put everything on one line.
Admin
select regexp_replace('/An/Ilegal%File', '[]/%ùòàè°$£&?§^()#+[;:@ç<>. ]', '_') from dual;
Admin
Yeah good job. Let's put that into prod. (:laughing:)
Admin
Remind me again why we're doing a roundtrip to the database to do string cleaning?
Admin
What's the result of the function when an exception is thrown? Does it rethrow after logging (TRWTF)? Or does it return some unexpected value?
Admin
Yea, not to mention why they (try to) remove the bad chars instead of doing it the proper way of only using the good chars (whitelist instead of blacklist).
Then you could use a regexp like this one (perl)
$tainted_var =~/([\w.-/\s]+)/; $sanitised_var = $1;
and be done with it.
It is actually one of the first things you should learn about user input, never try to remove the bad things, only get the good things (which you define explicitly) and discard the rest, as you will eventually miss one or more bad things if you try to do it the way it is done in this WTF.....
Admin
Admin
Wouldn't you keep that stuff in the application before it even hits stored procs?
Admin
But wouldn't THAT be the professional behavior? Saving valuable vertical screen space?
Admin
Retry, I suppose. Ignoring all exceptions. We can't bother the user with cryptic error message or risk any illegal character to pass, can we? [spoiler]see raw[/spoiler]
funmore sensible to log the exception? // oh, and while we're at it: don't forget to number those exceptions' messages // so that the logger won't suppress them }; }; ```Admin
If I saw this in code I had to maintain, I'd utter something filthy, too.
At least all the left parens make me feel at home, though.
Admin
I can't believe anyone would write that kind of code and not think "wait, I must be doing something wrong"...
Admin
Which, the article's WTF or the infinite recursion in my post? I mean, at least I knew that what I was writing was a joke...
Admin
Usually because you can't be certain that only one application will be writing to the same database, so the same methods need to be available to multiple programs.
Admin
And there's no better way of doing that than, say, a library?
Admin
What about when you need to fix a data validation bug? With a library, you have to update all the applications that use it.
Admin
The fact that you'd have to rewrite all library calls when you update a library kind of defeats the purpose of the library and is a bit of a WTF in itself...
Admin
The way they're using REPLACE, they could just do this:
I mean, assuming you have to use REPLACE this way—not that I see this as anything but idiotic—but assuming you did, your efficiency problem is REPLACE...the assignments wouldn't even be noticed.
So flatten it, yeesh.
Or is there some droid who goes around saying, "All those assignments are horribly inefficient, what's wrong with you, nest all those expressions or this code will be the cause of all our performance problems!"
Admin
YMBNH. People who only know how to use one tool use it all the time and don’t think twice about using it again, let alone whether another tool might do the current job better.
Admin
Oh, I'm not new at all on TDWTF... but even tough I've seen hundreds of WTFs, I keep being amazed at human stupidity.
Admin
Oddly enough, old versions of the Progress language preferred something like this. The language is compiled into some kind of pseudo-asm or something. Back in the 16-bit era, the compiled file had a bunch of 64K limits in it, including (oversimplified) a statement section. You had two ways of doing assignments,
That's three statements. On the other hand,
is only one statement. If a given program got close to the section limit you could make some headroom by combining assignments.
Admin
Not enterprisey enough. It needs more XML.
Admin
Wait, why put your code in a hidden div? And why in the world does Discourse let you create hidden divs?
Admin
Some questions are best left unanswered. "Why does Discourse...?" only leads to madness.
Admin
I suppose the real answer is "Because Jeff"
Admin
Eh, I'd rather use:
Although truthfully I'd rather see a whitelist method that would replace every character that's not in a valid list. That is to say, instead of replacing a fixed list of characters, you just replacing every character except, say, A-Z, a-z and 0-9.
Admin
What advantage does a library offer over a database function or stored procedure? You'd essentially have to have a different library for every platform and programming language you wanted to support, and you'd then have even more code to support and more code to worry about not being backwards compatible. What good is a data normalization function if any 3rd party would be virtually guaranteed to have a different version of it when you needed to update it?
Why do that when you get the exact same feature with a database function?
Admin
And why on earth does it not
Admin
I think it also isn't wonderful at doing sane stuff when you give it input with multiple non-ASCII characters in a row.
Admin
I know...but what's their excuse these days?
Admin
Well, they fixed the problem, for some values of "fixed". (That is to say, the fix was essentially a very large bandaid, one that makes the problem effectively never happen.)
Admin
Could be that this was inherited from an Oracle system prior to the advent of regexp_replace. I recall working on Oracle 8i systems that had no regex functionality, and syscalls were forbidden by DBA (unthinking) policy. I think I ended up with an array of characters i wanted to replace, and a loop over each character in the source string. Or maybe a bunch of substring and left()s or something.