Comment On A Spacy Problem

Like most of his past jobs, Don R started at a new company with high hopes and low expectations. And also like many of his past jobs, his dreams were quickly whisked away. This time, it happened on his first support ticket. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: A Spacy Problem

2009-12-07 09:04 • by Steenbergh (unregistered)
He shouda used this:

RemoveSpaces:
strItem = StringReplace(" ", " ");
if instr(" ") > 0 then goto RemoveSpaces

We don't need no regular expressions!

Re: A Spacy Problem

2009-12-07 09:04 • by MD (unregistered)
Boring!

Re: A Spacy Problem

2009-12-07 09:15 • by eViLegion (unregistered)
292587 in reply to 292586
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.

Re: A Spacy Problem

2009-12-07 09:17 • by Alekz (unregistered)
292588 in reply to 292587
eViLegion:
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.


No it does not suggest that.

Re: A Spacy Problem

2009-12-07 09:19 • by Rene (unregistered)
292590 in reply to 292587
strItem = StringReplace("Boring!", "WTF!");

Re: A Spacy Problem

2009-12-07 09:21 • by Mcoder
If there is a place to implement a recursive regular expression, that is it :) Way beter than just adding another StringReplace.

But, unfortunately, he does not seem to be working on Perl, and I know of no other language that permits such abuse on regexes...

Re: A Spacy Problem

2009-12-07 09:23 • by Michael (unregistered)
that must be the reason why his boss is now a manager and not developer anymore.

Re: A Spacy Problem

2009-12-07 09:25 • by NMe
Why use character classes in the regular expression if you're only matching a single character anyway?

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P

Re: A Spacy Problem

2009-12-07 09:25 • by eViLegion (unregistered)
292594 in reply to 292588
Alekz:
eViLegion:
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.


No it does not suggest that.


Oh, right, it suggests MD is a nob with nothing better to do that post an unconstructive single word answer, that is neither funny nor clever. And by extension, you are also one of those, for defending him.

Re: A Spacy Problem

2009-12-07 09:29 • by dkf
292595 in reply to 292591
Mcoder:
But, unfortunately, he does not seem to be working on Perl, and I know of no other language that permits such abuse on regexes...
It's not so much regexes at that point, as something that has the same syntax but isn't. (It's actually a context-free language and not a regular language, and so is matched by a different type of automaton. Assuming that nobody's been silly enough to go for the higher-level languages at that point; the complexity there starts to become a bit hard to work with.)

Re: A Spacy Problem

2009-12-07 09:35 • by Spudley (unregistered)
292596 in reply to 292593

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P


Hehe. I love regexes too, but I'd never claim that {2,} doesn't look weird.

Re: A Spacy Problem

2009-12-07 09:38 • by NMe
292597 in reply to 292596
Spudley:
Hehe. I love regexes too, but I'd never claim that {2,} doesn't look weird.

In that case:
regexReplace(itemDesc, " +", " ");

I realize this is different in the way that it also replaces " " with " " whereas my previous suggestion does not, but at least it couldn't look any simpler. :D

Re: A Spacy Problem

2009-12-07 09:38 • by Anonymous (unregistered)
292598 in reply to 292594
eViLegion:
...MD is a nob...

Question: are you four years old?

Re: A Spacy Problem

2009-12-07 09:41 • by adrian (unregistered)
292599 in reply to 292593
NMe:
Why use character classes in the regular expression if you're only matching a single character anyway?

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P


We should probably disambiguate, too, though:

regexReplace(itemDesc, "\s{2,}", " ");

There...that's clearer ;)

---

Captcha: delenit - the act of removing a nitwit?

Re: A Spacy Problem

2009-12-07 09:45 • by rwbthatisme (unregistered)
292600 in reply to 292599
adrian:


regexReplace(itemDesc, "\s{2,}", " ");



Be careful of using \s in regex as not all platforms support it.

Re: A Spacy Problem

2009-12-07 09:47 • by Edward Royce (unregistered)
292601 in reply to 292594
eViLegion:
Alekz:
eViLegion:
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.


No it does not suggest that.


Oh, right, it suggests MD is a nob with nothing better to do that post an unconstructive single word answer, that is neither funny nor clever. And by extension, you are also one of those, for defending him.


Boring!

Re: A Spacy Problem

2009-12-07 09:51 • by NMe
292602 in reply to 292599
adrian:
We should probably disambiguate, too, though:

regexReplace(itemDesc, "\s{2,}", " ");

There...that's clearer ;)

Depends on the actual situation I guess. From what I gather out of the article, it's always a space in machine generated code. You can get away without disambiguation in situations like that.

Re: A Spacy Problem

2009-12-07 09:56 • by Ben Jammin (unregistered)
292603 in reply to 292601
Edward Royce:
eViLegion:
Alekz:
eViLegion:
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.


No it does not suggest that.


Oh, right, it suggests MD is a nob with nothing better to do that post an unconstructive single word answer, that is neither funny nor clever. And by extension, you are also one of those, for defending him.


Boring!


Now that's funny!

Re: A Spacy Problem

2009-12-07 09:57 • by Spikey (unregistered)
292604 in reply to 292599
erm.. that may have unintended consequences, \s means any whitespace character not just space, gotta be carefull and make sure it does only what you want

Re: A Spacy Problem

2009-12-07 09:58 • by aristos_achaion (unregistered)
292605 in reply to 292596
Spudley:

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P


Hehe. I love regexes too, but I'd never claim that {2,} doesn't look weird.


Though, honestly, it looks less weird than itemDesc =~ s/[ ]{2}/ /g

TRWTF is that, not being written in Perl, this doesn't look like a cartoon character swearing, as God intended regexes to look.

Re: A Spacy Problem

2009-12-07 10:07 • by eViLegion (unregistered)
292606 in reply to 292603
Ben Jammin:
Edward Royce:

Boring!


Now that's funny!


Yes it is.

Shame the comment section has gone downhil so much in general though.

Re: A Spacy Problem

2009-12-07 10:15 • by Bubba (unregistered)
Clearly, the boss voted for Obama.

Re: A Spacy Problem

2009-12-07 10:18 • by James T. (unregistered)
Oh I favore my all time favorite wtf:

while(itemDesc != stringReplace(itemDesc, "  ", " ")) {

itemDesc = stringReplace(itemDesc, " ", " ");
}


no doubt it works ..... ^^

anyway ... I wondered why this "manager" did not fix the problem by increasing the number of spaces ... like

itemDesc = 

stringReplace(
stringReplace(
stringReplace(
stringReplace(
stringReplace(
stringReplace(
/* [...] snip for sanity */
itemDesc,
/* [...] yet another snip */
" ", " "),
" ", " "),
" ", " "),
" ", " "),
" ", " "),
" ", " ");


which would drastically increase efficiency !!1oneleven1!

Re: A Spacy Problem

2009-12-07 10:18 • by William Clark (unregistered)
292609 in reply to 292605
Spudley:

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P


Hehe. I love regexes too, but I'd never claim that {2,} doesn't look weird.


regexReplace(itemDesc, " +", " "); if you think {2,} looks weird... Or if braces are not supported on an implementation you find yourself using.

Re: A Spacy Problem

2009-12-07 10:21 • by William Clark (unregistered)
292610 in reply to 292609
William Clark:

regexReplace(itemDesc, " +", " "); if you think {2,} looks weird... Or if braces are not supported on an implementation you find yourself using.


That was supposed to be
"  +"
but it got eaten.

Re: A Spacy Problem

2009-12-07 10:29 • by justsomedude (unregistered)
TRWTF is allowing free-form field entries on a value that's getting fed to a 3rd party and is expected to match known possibles. Should be limited to list...

Re: A Spacy Problem

2009-12-07 10:32 • by luis.espinal
292612 in reply to 292585
Steenbergh:
He shouda used this:

RemoveSpaces:
strItem = StringReplace(" ", " ");
if instr(" ") > 0 then goto RemoveSpaces

We don't need no regular expressions!



Goto? Dude, what the...? Of all the things considering that DO/WHILE loops have existed since BASIC dialects evolved out of the GW-BASIC/PICK-BASIC/TARD-BASIC decades ago? Goto? Worst fix ever. I hope that was a joke.

As for the code snippet featured in the article, it is not surprising at all. It happens a lot, not only on VB, but on Java and C#. It almost makes me want to see programming licenses being mandatory to do perform any programming job or rigorous across-the-board examination exams mandatory for graduating with a CS or MIS degree... almost.

These type of WTFs are not just due to not knowing the language, but they display a fundamental flaw on the way of thinking and problem-solving, completely inexcusable.

-- second try --

Re: A Spacy Problem

2009-12-07 10:32 • by snoofle
292613 in reply to 292600
rwbthatisme:
adrian:


regexReplace(itemDesc, "\s{2,}", " ");



Be careful of using \s in regex as not all platforms support it.

So now we need to integrate xml into regular expressions!?


regexReplace(itemDesc, "<doc><charType>&nbsp;</charType></doc>{2,}", " ");

Re: A Spacy Problem

2009-12-07 10:34 • by Bubba (unregistered)
Spaces are good. They give the compiler time to think.

Re: A Spacy Problem

2009-12-07 10:37 • by Russell (unregistered)
292615 in reply to 292608
James T.:
Oh I favore my all time favorite wtf:

while(itemDesc != stringReplace(itemDesc, "  ", " ")) {

itemDesc = stringReplace(itemDesc, " ", " ");
}


no doubt it works ..... ^^

anyway ... I wondered why this "manager" did not fix the problem by increasing the number of spaces ... like

itemDesc = 

stringReplace(
stringReplace(
stringReplace(
stringReplace(
stringReplace(
stringReplace(
/* [...] snip for sanity */
itemDesc,
/* [...] yet another snip */
" ", " "),
" ", " "),
" ", " "),
" ", " "),
" ", " "),
" ", " ");


which would drastically increase efficiency !!1oneleven1!


See http://www.research.att.com/~njas/sequences/A159860 and http://www.research.att.com/~njas/sequences/A007501 for the most efficient sequence. In particular, sub-string lengths of 21, 6, 3, 2, and again of 2 spaces will reduce 460 and all shorter sequences of spaces to one space.

Re: A Spacy Problem

2009-12-07 10:41 • by Anonymously Yours (unregistered)
His boss should have resolved the problem by writing a script to write the script for him. It probably would have resembled this...


function genRepCodeForScriptWriter(intVersion)
{
strAnyCode = '';


//Double the number of string replaces for each iteration after the first, because that makes sense.
for(i = 0; i < intVersion; i++)
{
strAnyCode = strAnyCode + "\n\tstringReplace(";
}

//Squash itemDesc in the middle
strAnyCode = strAnyCode + "\n\t\titemDesc";


for(i = 0; i < intVersion; i++)
{
strAnyCode = strAnyCode + ",\n\t" + '" ", " ")';
}


//Wrap things up. Man, there is no easier way to do this.
strAnyCode = "// pull double spaces\nitemDesc = " + strAnyCode + ';';


return strAnyCode;
}

Re: A Spacy Problem

2009-12-07 10:43 • by blablablaadje (unregistered)
292617 in reply to 292591
Mcoder:
If there is a place to implement a recursive regular expression, that is it :) Way beter than just adding another StringReplace.

But, unfortunately, he does not seem to be working on Perl, and I know of no other language that permits such abuse on regexes...


Python does also permit such use, but then again, python just uses pcre like many other languages.

Re: A Spacy Problem

2009-12-07 10:45 • by Anonymously Yours (unregistered)
Wow, I made a massive logic error in my code there. Besides the one I made in deciding to write it, I mean.

Re: A Spacy Problem

2009-12-07 10:50 • by Neville Flynn (unregistered)
The appropriate thing to do in this economic environment with rising unemployment would have been to hire a data entry clerk to delete the spaces!

Re: A Spacy Problem

2009-12-07 10:50 • by Research Paper Reader (unregistered)
292620 in reply to 292615
Russell:
James T.:
anyway ... I wondered why this "manager" did not fix the problem by increasing the number of spaces ... like

which would drastically increase efficiency !!1oneleven1!


See http://www.research.att.com/~njas/sequences/A159860 and http://www.research.att.com/~njas/sequences/A007501 for the most efficient sequence. In particular, sub-string lengths of 21, 6, 3, 2, and again of 2 spaces will reduce 460 and all shorter sequences of spaces to one space.


Thanks Russell, for the link to your paper. Much more interesting than today's WTF.

Re: A Spacy Problem

2009-12-07 10:53 • by DT (unregistered)
292621 in reply to 292593
NMe:
Why use character classes in the regular expression if you're only matching a single character anyway?

regexReplace(itemDesc, " {2,}", " ");

This would do the exact same thing without looking weird. :P


It's regexp, everything looks wierd.

Re: A Spacy Problem

2009-12-07 11:08 • by Voice of Reason (unregistered)
There's far too much "clever" in these comments...

None of the RegEx is completely clear (it never is), nor is it remotely necessary.

while (itemDesc.indexOf(" ") != -1)
{
itemDesc = StringReplace(itemDesc, " ", " ")
};

Or was that too readable?

Re: A Spacy Problem

2009-12-07 11:11 • by realmerlyn
292623 in reply to 292617
blablablaadje:

Python does also permit such use, but then again, python just uses pcre like many other languages.


The joke there is that PCRE is not Perl Compatible, except in name. :) Should have been called "somewhat Perl Compatible" or maybe "Perl inspired". And until the PCRE lib embeds a full Perl interpreter, it'll never be truly "Perl Compatible".

Re: A Spacy Problem

2009-12-07 11:21 • by dkf
292624 in reply to 292622
Voice of Reason:
There's far too much "clever" in these comments...
So you decided to compensate?
Voice of Reason:
while (itemDesc.indexOf("  ") != -1) 

{
itemDesc = StringReplace(itemDesc, " ", " ")
};
You need to learn about Schlemiel the Painter and work out why that applies to your code.

Re: A Spacy Problem

2009-12-07 11:33 • by gallier2 (unregistered)
292625 in reply to 292624
What I thought at first look, but the complexity of his function is not quadratic (Schlemiel is O(n²)). It's less than that because StringReplace replaces more than 1 double white in each loop.

Re: A Spacy Problem

2009-12-07 11:42 • by Brooke (unregistered)
292626 in reply to 292588
Alekz:
eViLegion:
MD:
Boring!


And yet not quite boring enough for you to post a comment, thereby suggesting that your life must be even more so.


No it does not suggest that.

You're right; it doesn't suggest it. It confirms it, just like my life.

Re: A Spacy Problem

2009-12-07 11:46 • by gus (unregistered)
Dudes, it gets worse than this. At my last POE there were dozens of occurrences of:


while pos( ' ', Line ) > 0 do
Delete( Line, pos( ' ', Line), 1 );

Re: A Spacy Problem

2009-12-07 11:56 • by Voice of Reason (unregistered)
292628 in reply to 292624
Oh, I bow to your in-depth understanding of the implementation of your particular RegEx library.

Or, are you depending on the "Clever-Optimization" support that they're including new CPUs?

Perhaps the real "Schlemiel" is _assuming_ that an unknown implementation is faster that the direct route. Maybe you're right, but, it'll vary widely, and you certainly can't fault code that's clearer and _may not_ be any slower.

Re: A Spacy Problem

2009-12-07 12:01 • by NetBiter (unregistered)
TRWRTF is that Don was considering just adding another set of StringReplace()! I guess we should be thankful he didn't? Don is "growing."

Re: A Spacy Problem

2009-12-07 12:35 • by amischiefr
292631 in reply to 292612
luis.espinal:
Steenbergh:
He shouda used this:

RemoveSpaces:
strItem = StringReplace(" ", " ");
if instr(" ") > 0 then goto RemoveSpaces

We don't need no regular expressions!



Goto? Dude, what the...? Of all the things considering that DO/WHILE loops have existed since BASIC dialects evolved out of the GW-BASIC/PICK-BASIC/TARD-BASIC decades ago? Goto? Worst fix ever. I hope that was a joke.

As for the code snippet featured in the article, it is not surprising at all. It happens a lot, not only on VB, but on Java and C#. It almost makes me want to see programming licenses being mandatory to do perform any programming job or rigorous across-the-board examination exams mandatory for graduating with a CS or MIS degree... almost.

These type of WTFs are not just due to not knowing the language, but they display a fundamental flaw on the way of thinking and problem-solving, completely inexcusable.

-- second try --



Why almost? I think they should. You can't practice Law without a degree, you can't perform operations without a medical degree (legally anyway, which goes back to point 1...). Why not institute a similar practice for programming?

Oh right, because 1/2 of the tards out there are lazy, uneducated fucks that think because they write stupid script in their mother's basement that qualifies them as a programmer.

Yes I know, there are some talented guys out there that don't have a degree, yada yada, some exceptions to the rule, yada yada. And I'm pretty sure that there are people who could be good trial lawyers that can't get into Law school because they don't have the money or can't do well on the LSAT. But guess what? We don't let them practice law! And we shouldn't let just anybody write code.

Just my rant.

Re: A Spacy Problem

2009-12-07 12:48 • by Bubba (unregistered)
292632 in reply to 292631
amischiefr:
...we shouldn't let just anybody write code...


So stop employing just anybody... ;)

Re: A Spacy Problem

2009-12-07 13:10 • by Nonymous (unregistered)
292633 in reply to 292631
amischiefr:

Why almost? I think they should. You can't practice Law without a degree, ...


Some states let you take the Bar exam without having a degree, and some states don't even require you to take the Bar exam to practice law (voluntary membership in the Bar).

Not that I disagree with you, but Law is not the best example of your point.

Re: A Spacy Problem

2009-12-07 13:10 • by Patrick (unregistered)
Just another reason why RegEx Rules!

/h[a4@](([c\(][k\|<])|(x))\s+((d)|([t\+]h))[3ea4@]\s+p[1l][a4@]n[3e][t\+]/i

Re: A Spacy Problem

2009-12-07 13:18 • by wee
292636 in reply to 292599
adrian:

We should probably disambiguate, too, though:

regexReplace(itemDesc, "\s{2,}", " ");


I was thinking the same thing, but if it's only one pattern that is only a couple characters long, I'd use something literal, like this:

regexReplace(itemDesc, " ", " ");

That looks much clearer to me, as I immediately know what you are aiming to do.

Additionally, the problem with using \s is that it'll match spaces, tabs, newlines, carriage returns, etc. So if that "\s{2,}" regex is run across a document created/saved on a Windows platform, it'd replace any blank lines with spaces (by matching Windows' carriage return/linefeed line endings). That's probably not what you want.

Re: A Spacy Problem

2009-12-07 13:20 • by Patrick (unregistered)
292637 in reply to 292608
hmm. well, going that way, for efficiency's sake, start with 16 spaces, then 8, 4, 2, and if there are any doubles remaining, loop back to the check for 16


then again, what are they doing that would result in so many contiguous spaces in the description?

http://thedailywtf.com/Articles/No_Line_Breaks_0x3f__Aaaaaaaaaaaaaa!_.aspx
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment