Comment On Third Time's a Charm

Starting a new job is usually exciting but also frightening. Adjusting to a new code base --- styles, idioms, and all --- can be daunting. Luckily, for Sam, all the important code is kept in a single file: MyStuff.asp. Despite the name, the functions in that file belong to everyone. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Third Time's a Charm

2007-03-22 09:06 • by Helten (unregistered)
Confusing naming, you say? Isn't it obvious that removeNumeric() is supposed to remove everything _except_ numeric chars? :)

Re: Third Time's a Charm

2007-03-22 09:11 • by Will (unregistered)
I'm no VB developer, but I doubt very much that the last one will even work. NumStriper != NumStripper.

Re: Third Time's a Charm

2007-03-22 09:17 • by Will Perdikakis (unregistered)
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.

Re: Third Time's a Charm

2007-03-22 09:22 • by James (unregistered)
Also 2nd one won't work. outStr != outString

Re: Third Time's a Charm

2007-03-22 09:28 • by RON (unregistered)
127941 in reply to 127936
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.



Fail.

Re: Third Time's a Charm

2007-03-22 09:33 • by foxyshadis
127944 in reply to 127933
Will:
I'm no VB developer, but I doubt very much that the last one will even work. NumStriper != NumStripper.

James:
Also 2nd one won't work. outStr != outString

Presuming they're typos, but if not, oh the fun of ensuring that there's no option explicit in sight!

(OTOH I forget whether classic asp is vb6 or vbscript; the latter has no declarations at all in a classic invitation to shoot yourself in the foot. Repeatedly.)

Re: Third Time's a Charm

2007-03-22 09:41 • by Sgt. Preston (unregistered)
127946 in reply to 127944
foxyshadis:
(OTOH I forget whether classic asp is vb6 or vbscript; the latter has no declarations at all in a classic invitation to shoot yourself in the foot. Repeatedly.)

Classic ASP uses VBScript, which has very loose run time typing and implicit variable declaration. Quick and easy to write and quick and easy to screw up if you're not careful.

Re: Third Time's a Charm

2007-03-22 09:41 • by Pig Hogger (unregistered)
This is great!

In fact, this is just the way the PHP functions were developped!

It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!

Captcha: "poindexter". WTF????

Re: Third Time's a Charm

2007-03-22 09:47 • by Sgt. Preston (unregistered)
127949 in reply to 127947
Pig Hogger:
It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!

Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.

Re: Third Time's a Charm

2007-03-22 09:52 • by Blame (unregistered)
127950 in reply to 127941
RON:
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.



Fail.

Spot on, Ron.

Re: Third Time's a Charm

2007-03-22 09:53 • by jonny lech (unregistered)
Eat it VB. Java pwnage:

public String stripNumbersFromString(String s)
{
return s.replaceAll("\D", "");
}

Re: Third Time's a Charm

2007-03-22 09:53 • by Raptor (unregistered)
Sorry, but I don't see how this is a WTF at all. Something to read, shrug and move on, certainly wouldn't make me think "WTF" :)

Re: Third Time's a Charm

2007-03-22 09:57 • by Sgt. Preston (unregistered)
It wouldn't be a WTF discussion without someone coming to the defense of the WTF. So, I'll offer the following.

At least the first function, "OnlyNumber", has a tolerably meaningful name and actually does what it appears to claim. It uses the bizarrely named variable "sNonNum" for the string of numeric characters, but that's inside the 'black box'.

As for including a whole library of community developed functions in every script on the Web site, well... WTF indeed!

Peer review, weeding, and thorough documentation could still make it a handy resource.

Re: Third Time's a Charm

2007-03-22 10:00 • by blah (unregistered)
127954 in reply to 127933
Thats obvious. its actually NumStriper <> NumStripper

Re: Third Time's a Charm

2007-03-22 10:05 • by Luke Dawson (unregistered)
127955 in reply to 127936
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.


Ah, well that's OK then.

Re: Third Time's a Charm

2007-03-22 10:05 • by Will (unregistered)
127956 in reply to 127954
blah:
Thats obvious. its actually NumStriper <> NumStripper


Hey, at least it wasn't NunStripper...

Re: Third Time's a Charm

2007-03-22 10:10 • by EmmanuelD (unregistered)
I actually love the name of the second one: removeNumeric().

So that's supposed to remove all numbers in the string. And of course, the code do the exact contrary (well, the code doesn't work, unless this is a typo from our master poster).

I guess there is a meta-function somewhere which is called removeNameSecmantics() (or addNameSemantics(), depending on the programmers way of thinking).

The captcha says it all: muhahaha.

Re: Third Time's a Charm

2007-03-22 10:10 • by akatherder
127958 in reply to 127951
jonny lech:
Eat it VB. Java pwnage:

public String stripNumbersFromString(String s)
{
return s.replaceAll("\D", "");
}


Wow! VB supports regular expressions too.

Re: Third Time's a Charm

2007-03-22 10:13 • by A Nonny Mouse (unregistered)
i like that they have such good naming conventions though

sStr, inString, str

nice...

Re: Third Time's a Charm

2007-03-22 10:13 • by suutar (unregistered)
I like the way all three of them will turn, e.g. "a1b2c" into "12"...

Re: Third Time's a Charm

2007-03-22 10:13 • by etr (unregistered)
127961 in reply to 127951
jonny lech:
Eat it VB. Java pwnage:

public String stripNumbersFromString(String s)
{
return s.replaceAll("\D", "");
}


Yeah, and you can do the same thing (roughly) in PHP, or Javascript, or any language with regex capability...

Is there no regex in VB? Why would anyone use that language?.... That's a real WTF... :P

Re: Third Time's a Charm

2007-03-22 10:15 • by EmmanuelD (unregistered)
127962 in reply to 127952
Raptor:
Sorry, but I don't see how this is a WTF at all. Something to read, shrug and move on, certainly wouldn't make me think "WTF" :)


If it's not a WTF, then it's because there's only 3 of them. You must have many more code repetitions to make this kind of "quite normal behavior" a WTF. For my part, I can't consider this kind of issue to be a WTF unless there are at least 31 of them (and that's because I'm 31. In 4 years, this maximum repetition number should increase).

Re: Third Time's a Charm

2007-03-22 10:15 • by dhromed
127963 in reply to 127936
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.


While a library often contains similar/related functionality (different but similar ways of pouring database results into a language-native format, for example), a library with exact copies of functionality is in dire need of cleanup.

This WTF is a WTF indeed, because it displays the utter mental blindness with which their library is treated.

Re: Third Time's a Charm

2007-03-22 10:16 • by EmmanuelD (unregistered)
127965 in reply to 127960
suutar:
I like the way all three of them will turn, e.g. "a1b2c" into "12"...

Yeah!

They look like similar functions!

Re: Third Time's a Charm

2007-03-22 10:19 • by Sgt. Preston (unregistered)
127966 in reply to 127961
etr:
jonny lech:
Eat it VB. Java pwnage:

public String stripNumbersFromString(String s)
{
return s.replaceAll("\D", "");
}


Yeah, and you can do the same thing (roughly) in PHP, or Javascript, or any language with regex capability...

Is there no regex in VB? Why would anyone use that language?.... That's a real WTF... :P


Isn't it interesting how quick people are to slam Visual Basic, VBScript, and VN.NET without (a) knowing the differences among them or (b) knowing the features and capabilities of the languages.

What we saw in this WTF was VBScript. All three of the VB-related languages support regular expressions.
http://msdn2.microsoft.com/en-us/library/ms974570.aspx

Re: Third Time's a Charm

2007-03-22 10:20 • by Sgt. Preston (unregistered)
127967 in reply to 127966
Pardon my typo. "VN.NET" of course should have been "VB.NET".

Re: Third Time's a Charm

2007-03-22 10:36 • by ParkinT
NumStriper()?
How do you add 'stripes' to a number?

Re: Third Time's a Charm

2007-03-22 10:50 • by I Hate 1st TN Bank (unregistered)
127973 in reply to 127951
Aren't regular expressions available in just about every language under the sun? This is not a problem with VB (although I would never use it over C# or JavaScript), it is a problem with the one(s) behind the keyboard. Unfortunately, we can't put monkeys in space, that's why there's still so many in front of computers...

Re: Third Time's a Charm

2007-03-22 10:54 • by MrBester
OnlyNumber only returned numbers. Perhaps that is what was wanted, but some numbers have a decimal component that wouldn't be honoured.
As for the glorious WTFy way Microsoft decided to implement RegExp in VBScript:

Dim reg, sOut
Set reg = New RegExp
reg.Global = True
reg.Pattern = "\D"
sOut = reg.Replace(input, vbNullString)
Set reg = Nothing

Re: Third Time's a Charm

2007-03-22 11:00 • by etr (unregistered)
127975 in reply to 127974
MrBester:
OnlyNumber only returned numbers. Perhaps that is what was wanted, but some numbers have a decimal component that wouldn't be honoured.
As for the glorious WTFy way Microsoft decided to implement RegExp in VBScript:

Dim reg, sOut
Set reg = New RegExp
reg.Global = True
reg.Pattern = "\D"
sOut = reg.Replace(input, vbNullString)
Set reg = Nothing



Ouch!

Re: Third Time's a Charm

2007-03-22 11:01 • by RevEng
127976 in reply to 127968
ParkinT:
NumStriper()?
How do you add 'stripes' to a number?


Turn on every other bit?

Re: Third Time's a Charm

2007-03-22 11:07 • by vt_mruhlin
127977 in reply to 127949
Sgt. Preston:
Pig Hogger:
It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!

Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.


It's perfectly cromulent code, which imbiggens the functionality of the language.

Re: Third Time's a Charm

2007-03-22 11:17 • by Reaver (unregistered)
127979 in reply to 127968
ParkinT:
NumStriper()?
How do you add 'stripes' to a number?


Maybe it has something to do with the Webserver's RAID configuration?

Nah, probably the same thing that makes "developpers" play "Rouges" in fantasy games.

Or the disappointment felt when one discovers that there are only "stripers" at the nightclub.

Cheers!

Re: Third Time's a Charm

2007-03-22 11:21 • by Manni
127981 in reply to 127975
etr:
MrBester:
OnlyNumber only returned numbers. Perhaps that is what was wanted, but some numbers have a decimal component that wouldn't be honoured.
As for the glorious WTFy way Microsoft decided to implement RegExp in VBScript:

Dim reg, sOut
Set reg = New RegExp
reg.Global = True
reg.Pattern = "\D"
sOut = reg.Replace(input, vbNullString)
Set reg = Nothing



Ouch!


VB does have its share of WTFs, like finishing out the function with functionName = value rather than using the return statement like everyone else. Small typos like we see in the sample above will result in a returned value of a zero-length string. Yippee.

And although it is possible to create a RegEx object in VB, I wouldn't recommend it if you have to do it more than a couple times. It's incredibly slow to instantiate. Not that VB is known for its speed, but don't slow it down any more than you have to.

If you're dealing with fairly short strings, just loop through it with Mid(), save the RegEx stuff for when it would be worthwhile.

Re: Third Time's a Charm

2007-03-22 11:38 • by Leibnitz27 (unregistered)
I moved onto a 750kloc project once, and found 7 functions which operated on the same container type, all called "remove_duplicates" (with minor changes / namespace hiding).

Catchpa : Bling - Programming's glamorous you know.

Re: Third Time's a Charm

2007-03-22 11:42 • by jgreen
Having been forced to use ASP in the past, I defied convention and used Javascript as the language instead of VBScript because of the nightmarish state of VBScript. Also making sure to always explicitly declare and explicit type conversion was extremely helpful as well.

Even so, I also had to resort to (albeit much shorter) a custom defined "library" for dealing with the bizarre XML RPC I was forced to use for communication with our CRM system (that drives the website).

Re: Third Time's a Charm

2007-03-22 11:49 • by cparker
127985 in reply to 127951
jonny lech:
Eat it VB. Java pwnage:

public String stripNumbersFromString(String s)
{
return s.replaceAll("\D", "");
}
Wow, you're cool.

Function stripNumbersFromString(ByVal s)

Dim re
Set re = new RegExp
re.Pattern = "\d"
re.Global = True

stripNumbersFromString = re.Replace(s, "")
End Function
\d matches numeric characters.
\D matches non-numeric characters.

Re: Third Time's a Charm

2007-03-22 11:55 • by Will (unregistered)
127986 in reply to 127985
cparker:

End Function[/code]\d matches numeric characters.
\D matches non-numeric characters.


According to the article, the submitter was looking for a function to return the numeric characters out of a string. So, what is wanted is to replace non-numeric characters with "". \D would be correct.

Re: Third Time's a Charm

2007-03-22 11:59 • by cparker
127987 in reply to 127986
Will:
cparker:

\d matches numeric characters.
\D matches non-numeric characters.


According to the article, the submitter was looking for a function to return the numeric characters out of a string. So, what is wanted is to replace non-numeric characters with "". \D would be correct.
Yes, but the GGP comment was a new function with a new function name. I fixed the pattern to match what the function name said it was doing.

Ever hear of the saying "say what you mean and mean what you say"?

Re: Third Time's a Charm

2007-03-22 12:00 • by PC Paul (unregistered)
127989 in reply to 127956
Will:
blah:
Thats obvious. its actually NumStriper <> NumStripper


Hey, at least it wasn't NunStripper...

Why would I want to stripe a Nun?

Re: Third Time's a Charm

2007-03-22 12:05 • by Will Perdikakis (unregistered)
127990 in reply to 127963
dhromed:
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.


While a library often contains similar/related functionality (different but similar ways of pouring database results into a language-native format, for example), a library with exact copies of functionality is in dire need of cleanup.

This WTF is a WTF indeed, because it displays the utter mental blindness with which their library is treated.
The problem is, you can not just go to the library and determine the best function for the job and delete the other two because there may be some remote code that uses this library. You will break that code.

This problem is inherent in user editable function libraries. Just like the possibility of errant code getting in there. Just like possibility of bad information getting on Wikipedia.

And to all those one-word replies to the original post, please explain what you disagree with.

Re: Third Time's a Charm

2007-03-22 12:10 • by James (unregistered)
Don't you get it? "RemoveNumeric" removes the numeric characters... and returns them! Get it? Huh? Huh???

Wow, tough crowd.

Re: Third Time's a Charm

2007-03-22 12:13 • by Jimmy (unregistered)
127993 in reply to 127977
vt_mruhlin:
Sgt. Preston:
Pig Hogger:
It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!

Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.


It's perfectly cromulent code, which imbiggens the functionality of the language.


I concellate. It's a snaff way of bedroggling.

Re: Third Time's a Charm

2007-03-22 12:14 • by Patrick (unregistered)
NumStriper? does it paint the numbers with stripes?

Captcha: xevious - You know I dont' speak Spanish!

Re: Third Time's a Charm

2007-03-22 12:20 • by Paul (unregistered)
127996 in reply to 127987
If you want to strip the numbers from the string, you use \D. You fixed it backwards.

Re: Third Time's a Charm

2007-03-22 12:25 • by real_aardvark
127997 in reply to 127990
Will Perdikakis:
dhromed:
Will Perdikakis:
This is not a WTF. When you have a shared function library, you will always have repeated functions, or functions that are really similar but take in account a different range or type of input.

This will always happen.


While a library often contains similar/related functionality (different but similar ways of pouring database results into a language-native format, for example), a library with exact copies of functionality is in dire need of cleanup.

This WTF is a WTF indeed, because it displays the utter mental blindness with which their library is treated.
The problem is, you can not just go to the library and determine the best function for the job and delete the other two because there may be some remote code that uses this library. You will break that code.

This problem is inherent in user editable function libraries. Just like the possibility of errant code getting in there. Just like possibility of bad information getting on Wikipedia.

And to all those one-word replies to the original post, please explain what you disagree with.

Well, apparently two of the three basically do nothing. In the remote likelihood that they are used anywhere, I suspect that a simple refactoring to no-op would be an improvement.

In the more general case, a refactoring of all but one function such that they are implemented in terms of the remaining (useful?) one is obviously the way to go. This makes the lives of future developers significantly less likely to end in That Postal Moment.

As to the one-word replies, I think the authors are implying that they would not wish to work alongside someone with your refreshingly cavalier attitude to sensible codebase maintenance. This is most unfair of them. If they look around their place of work, I have no doubt they'll find plenty of other ninnies who are equally adept at making their lives miserable.

Re: Third Time's a Charm

2007-03-22 12:30 • by Phyzz (unregistered)
127999 in reply to 127949
Sgt. Preston:
Pig Hogger:
It’s the "it doesn’t exist, just add it to the language" school of language definition at it’s finest expression!!!

Rather like the English language, except that in English, we don't care whether a we already have eighteen ways to say something; we'll add a nineteenth and call it cool. And we don't care whether the expression we invent already exists with an unrelated meaning; we'll just give it another one. Sort of spoken language overloading run amok.


Helped out by the fact that English is a ridiculously loosely typed language. What were they thinking. Theres even the word "verbed" for implicit conversion of noun type objects to a verb object. Which is itself verbed noun. What a WTF. :D

Re: Third Time's a Charm

2007-03-22 12:33 • by Will (unregistered)
128000 in reply to 127987
cparker:
Yes, but the GGP comment was a new function with a new function name. I fixed the pattern to match what the function name said it was doing.

Ever hear of the saying "say what you mean and mean what you say"?


The name "stripNumbersFromString" is a little ambiguous. It could mean "strip the numbers from the string and give the string back to me" or "strip the numbers from the string and give the numbers back to me."

Re: Third Time's a Charm

2007-03-22 12:39 • by Paul (unregistered)
128003 in reply to 128000
"strip" is synonymous with "discard". You don't want back what you discard.

Re: Third Time's a Charm

2007-03-22 12:44 • by Andrew (unregistered)
128004 in reply to 127989
PC Paul:
Will:
blah:
Thats obvious. its actually NumStriper <> NumStripper


Hey, at least it wasn't NunStripper...

Why would I want to stripe a Nun?


To send her to prison.
« PrevPage 1 | Page 2Next »

Add Comment