- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- Three Little Nyms
- Tangled Up In Blue
-
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
Not *all* of them. Only the first one [;)]
Admin
While all the WTFs in this have been commented exccessively, no-one has mentioned the redundant assignment of sNewName. Really, it should be an If .. Then... Else rather than a pre-assignment followed be a change, purely based on a assembly code view. Single hits to memory are always better than two.
Admin
But since you need to call Instr regardless to determine whether there's an apostrophe in the name, why not store that value in a variable and not call Instr again?
Sure, it's not going to bring your program to its knees, but calling any function twice in a row to get the exact same result when you can store that result is bad design.
Admin
I think the WTF here is the variable naming conventions. Prefixing s to strings, and i to integers. While such an idea might be a nice thought, it's mostly useless in practise. Not to mention that it makes the code visually unappealing, which is one of the most important aspects of good code, in my opinion.
Admin
Man I had to look all the way to the bottom for someone to say Option Explicit. Not too many VB programmers here?
Admin
Haha! You must be a troll. Welcome to the party, sit down, and have a beer.
Admin
Go grab a VB book that is pre .Net and one of the first two chapters will tell you to put sString, iInteger, oObject, dDoble, frmForm, cmdCommandButton..... it's a VB(very basic) thing.....
Of course now M$ has retracted that in lue of
Dim ThisISAnIntegerForCountingThingsWhileILoopInAForLoop01 As Integer
Dim ThisISAnIntegerForCountingThingsWhileILoopInAForLoop02 As Integer
Dim ThisISAnIntegerForCountingThingsWhileILoopInAForLoop03 As Integer
Admin
It's surely bad design to introduce an extra variable just to store a simple computation.
Admin
Yeah! You should just do the computation over and over. Why use a *variable* to store info ! yuck! What kind of idiot programmer would do that? Why did they ever even invent those stupid things, who needs them?
(I can only imagine if this guy was my boss ... "Uh, Jeff, nice code but what's up with the variables? Can we lose those? I heard somewhere that storing simple computations in variables is an indicator of bad software design")
Admin
First, it does not "replace" the single quote chars found in the orginal string. It does return a string supposedly with all the ' replaced by `.
And then the logic replaces only the first ' found in the string, and immediately returns. Either you need a for loop in this method, or you can call this method recursively on the string until all ' are replaced.
And there's no need to introduce the local variable sNewName!
I found only three :-(
Admin
I once did something similar because that was the way management wanted it. The GUI the salespeople used was perfectly capable of dealing with names like O'Hara and storing them safely in that form, but for some reason they had been told to enter that as OHARA instead. My procedure, which worked on data from a web form, was required to do the same thing for consistency: uppercase it and strip out any ' characters.
As an added bonus, the president of the company was of Irish descent and ... yes, indeed ... his own name, mangled, was one of the first rows in the customer table.
I'm not claiming this was a good idea, just saying -that particular decision- may not have been the programmer's fault.
Admin
To be fair, VB 5.0 and older didn't have a Replace function.
Doesn't forgive this broken crap though.
Admin
I see the biggest WTF of them all-and the one everyone missed. It's the very first thing there: `is not an apostrophe. Even worse, it's actually an opening single quote. This thing is doing the inverse of what it purports to be doing, and, appearantly, not even doing it right. Unprononcable scream.
Admin
The real WTF is the fact that this person has re-invented the square wheel. If you were to use a parameterized query (whether it's inline or a stored proc), then as long as you're not using dynamic SQL then your problem will just go away. Any hacker will sit there until doomsday and they won't be able to inject nuffink, geddit ?