- 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
Actually,
This could be a hold over from the VB5 days when there was no such thing as a replace function.
Admin
Even still, they could've replaced the implemenation of the function to just use Replace, even if they wanted to leave the method in there.
Admin
check out this function written by a Sr. Dev where I work, he could have user Replace(str,"'","''")
'Function: QuoteForFilter
'Description: This function returns the passed string with single quote(')
'characters replaced with two single quote characters. Prepares the
'string to be used as part of a RowFilter expression.
'For example:
' QuoteForFilter("PIG'S FEET") returns "PIG''S FEET"
Private Function QuoteForFilter(ByVal criteria As String) As String
Dim alCharBuffer As New System.Collections.ArrayList(criteria.Length)
Dim c As Char
For Each c In criteria
alCharBuffer.Add(c)
If c = "'"c Then
alCharBuffer.Add("'"c)
End If
Next
Return New String(CType(alCharBuffer.ToArray(GetType(Char)), Char()))
End Function
Admin
Although piss funny, I'm with Mike.
After developing a whole lotta shit in j1.4 I find out that the client is still on 1.3 (yes, I believed them when they said 1.4). As a result I had to write my own split and replace functions.
Admin
The mobile JVM for WinCE we're using implements java 1.1 spec. How much NIH do you think we have had to do...?!?
Before you ask, I don't know why we're using Java on PocketPC either.
Admin
"This could be a hold over from the VB5 days when there was no such thing as a replace function."
It wasn't. The first version of this software was written in VB6 SP5.
Admin
"It wasn't. The first version of this software was written in VB6 SP5"
Like I said.. it could be. Obviously, this was not the case in this instance.
Heh, I remember how relieved I was when I found out VB6 had a replace function. That meant I could rip out the several dozen instances of the function from our software ;)
Why someone would ever want to roll their own on something like this in VB is incredible. This is slower (and obviously, more complicated) than just using Replace.
Admin
jesus h christ! or you could do something like:
$somestring =~ s/[c]+//g;
in a language with Perlish regular expressions, where c is the character to whack.
Admin
modern languages have a huge number of builtins
this does not mean that every coder knows every builtin of every language they use
Admin
That's what language/function references are for.
One of the most reliable ways to produce WTFs is to code without a net manual.
Admin
We've got a boatload of code where I work that exhibits this quality. I stripped a good deal of it out a couple of years ago, but our most persistent offender (used in far too many places to remove) is CopyChars().
CopyChars() is basically strncpy().
Admin
Okay, but you have to get your coffee and settle into your easy chair and read the reference from front to back. Either that or study all of the "What's new?" section of the documentation. You can't just go looking up new keywords by intuiting them.
Imagine our author above, moving from VB5 to VB6 and hoping they've added a character removal routine, so he does a search on "stripChar", "charStrip", "charRemove", "stringRemove", "charDelete", and any other targets he can think of that would describe removing a character from a string. But because he's trying to remove a character, not swap it for something else, it never occurs to him to look for "replace".
Admin
That's a good theory, except that googling for "vb6 remove characters from string" gives you this as the first result: http://www.codeguru.com/vb/gen/vb_misc/text/article.php/c2739/
Google. It's like the ultimate reference manual.
Admin
I wonder if he wrote his solution faster than you could implement something you found via a search engine.
Admin
Reinventing the wheels isn't necessarily a bad thing to do.
In some languages, like AS3, building your own version of built-in methods can be very useful, especially if you're looking for soem performance improvements.
A good example of this would be to inline your own version of Math.abs() or pretty much anything of the Math class.
Not having to call the method from an external class and doing some improvements (like building some bitwise hell) can result in a method that returns the same than the built-in one, but that will also run hundreds (and sometimes thousands) of times faster.