- 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 has Nagesh written all over it.
Admin
Just wow...
Admin
Nagesh, take a bow... You are now officially a meme (to the 6 people that frequent this site).
Admin
So, what happens when phone numbers go hex?
Admin
Admin
You rewrite the code (even this shitty code) to support it. You don't code to prospective realities, you code to the current reality.
Although I imagine that would be a great WTF. "Some junior decided that phone numbers might be in hex someday, so he wrote a bunch of code to support it. He has another few months of beatings to endure."
Admin
Oh. Oh God.
...I thought Python was relatively free of WTF programmers (myself excluded, of course).
Admin
I'd give the guy some credit if he even put it in a "reusable" method for each field...what am i thinking???
Admin
Look hang on, I'm not so sure this will work. I'm not sure about the "replace" function. What if it only replaces the first instance of the character? I'm worried this isn't going to catch every instance of iffy characters (and I haven't got time to read the documentation), so I reckon:
homephone[1] = homephone[1].replace(" ", "").replace("-", "").replace("(", "") : :
homephone[2] = homephone[2].replace(" ", "").replace("-", "").replace("(", "") : :
... and so on ought to do it. Um, how long can this string be, by the way ...?
Admin
Please help me, do you have a unicode version?
Admin
LIKE IT!
On a side note: We need a "I like it" button or other way to rate comments
Admin
Admin
This is only a WTF because the guy didn't use a for loop.
If you saw this code you would definitely think it was bad, but not worthy of a daily wtf. Can we get real articles please?
Admin
Admin
No - a monkey wouldn't have the attention span to come up with something this long and repetitive. Besides, they tend to throw the crap at their peers directly, rather than leaving it for the next generation of monkeys to find in a few years time...
Admin
Depending on the language, the replace() code may actually be using regexes internally. Java's String.replaceAll() method takes a regex as the first parameter, so it's not inconceivable that this unspecified language is already using a spectacularly ineffecient number of regular expressions.
Admin
Nice use of fluent programming style.
Admin
Sure, like an outer join to 3 different databases; one for each type of phone number. This allows for flexibility if home/work/cell phone numbers start to have different characteristics. And, if different types of phone numbers are required in the future, just copy a database, some quick editing, and add another join.
Admin
TRWTF: You only wrote six sentences and still managed to make a typo on "regular" and misspell "weird".
Admin
Homophone? What like there, their and they're?
Admin
Yeah, and then a non-perl developer like me comes along later forced to make sense of your perl script and sees "tr/0-9//cd" and says WTF? At least I could look at today's TDWTF code and get an idea of what it does.
Admin
comment down the bottom
and we will add a nice story for akismet, too. I wonder if it might be because there are too many commas vs characters in the post. How far would I need to go to balance this out? So far, I have tried to post 3 times, but clearly I'm not fooling akismet who knows better. Maybe I will simply write some big long sentences without any puctuation to see whether we can get something through we have already tried to post five times and each times akismet was not happy still I suppose it is far far better to encourage people to go to the effort of writing soliloquies to avoid the spambot rather than risk a couple of adds for nike shoes. Maybe we will try something differet I wonder if akismet likes poetry: There was movement at the station for the word had got around that the colt from old regret had got away
Or maybe It was somewhere in the country in a land of rock and scrub that they formed an institution called the Geebung Polo CLub
Admin
Most of the time perl regular expressions look like total garbage and cannot be deciphered. But come on, you couldn't spend all of 2 minutes to look this one up online?
Admin
Why are we always so obsessed with Data formats? It seems to go against internationalization and other ideas. I frequently get sick of (online) forms that don't let me proceed without adding some mundane detail that is not relevant to them. Further, by insisting that I enter 'realistic' values in the fields they feel are important, they are making it a lot harder for themselves (somewhere down the track) to verify whether my submission is genuine.
If someone doesn't give a valid looking email address, and you feel that a valid address is important, you can ignore their submission on the backend without bothering them on the front end. There is a principle in Data Matching that raw data usually provides more value and more indentification detail than any efforts to scrub, enhance or 'fix' the data.
Telephone numbers come in many formats around the world, and given the way they are structured it is quite possible that the spacing or other punctuation may give some identification as to where it comes from (where as stripping it might make two totally different numbers from two totally different locales appear similar).
Observe some numbers from different parts of the world (they have been changed from existing numbers I found, and it's possible that some of them are no longer valid after my changes, but hopefully they illustrate the point): US: +1 847 576 6246 Czec Republic: +52 (55) 5243-6123 Indonesia: (62-21) 571-8855 UK: +971 4 33 15 476 Italy: +39 02545371 Australia: +61 3 9856 7698 Each of them has a different spacing, and some have brackets and dashes, but the format is relevant. What if we remove it? 18475766246 525552436123 62215718855 97143315476 3902545371 61398567698 Of course, the area codes should dictate that we never get duplicates, but what if people don't use full area codes? How many people use full (national and) international prefixes when submitting phone numbers online?
Of course, if the system in question was insignificant and was only for Fr Brian to keep track of parishioners, there's no issue, but if this is on a system that has global reach and might (whether today or in the future) need to be able to store multiple locale's phone numbers, then this solution is naive at best. It might be desirable to validate that phone numbers are in a prescribed format (someone bodgey from Russia {for example} might not know conventions used in the US to write phone numbers) but even this shouldn't necessarily be articulated to the end user (but rather dropped silently into a 'look at later' file).
There is much more that could be said, but ultimately, the real WTF is people who insist on trying to validate or alter potentially global data. Forcing someone to observe a specific format (whether in numbers or addresses or something else) will increase the number of bad results you get because users will try to beat the system with another value. Many (American) sites have options for people from outside the US to enter data, but still have requirements on either state or zipcode fields. Sites like this will get many people from elsewhere enter anything the validator accepts to get over this requirement. The only effect is that the data is suddenly compromised.
But who cares, right?
Admin
It's good to know that ",__?" is a valid phone-number. Too bad I can't try dialing it - all my phones, and Skype too, are lacking the necessary buttons, unfortunately.
Admin
Both the person who wrote the requirements and the person who implemented them has no understanding of telephone numbers.
It amazes me how many web sites out there validate phone numbers as "Long Integer", or worse, "Long Integer starting with 0". Clueless.
And without the brackets and plus symbol, the user does not know what to dial when using the stored number, which defeats the purpose of storing it in the first place.
Admin
You could kill that with a backslash
Admin
I'd prefer this, regex is for pussy's:
String newPhoneNr = ""; for(int i = 0; i < phoneNr.Length; i++) if(phoneNr[i] == '0' || phoneNr[i] == '1' || phoneNr[i] == '2' || phoneNr[i] == '3' || phoneNr[i] == '4' || phoneNr[i] == '5' || phoneNr[i] == '6' || phoneNr[i] == '7' || phoneNr[i] == '8' || phoneNr[i] == '9') newPhoneNr += phoneNr[i];
Admin
Brilliant, you found a way to make the code worse. Now you don't just have a cumbersome way to filter out (some) characters from the phone field, you've also arbitrarily restricted yourself to US numbers. Since obviously you'll never have a customer who isn't a US citizen or a US citizen who happens to live abroad...
Admin
What if the user start inputting chinese characters ? This implementation is a good start just incomplete, you need to extends this to exclude the whole non numeric UTF-8 + the Klingon alphabet.
Also insert these characters on a reference data table so that you can adapt the exclusion list without code changes, for complete future proofness and flexibility.
These sloppy developers, always taking the easy way out !
Admin
I think a lot of these comments nicely highlight a common problem I see when people first learn regexes - they think they're the holy grail to every string manipulation problem out there. "But I can do this with one simple regex"! Simple for you but wasteful and labour intensive for your processor. This isn't about premature optimisation, it is about avoiding hugely costly tasks for simple and repetetive jobs. If you don't understand that, you will never be a good coder.
"Some people, when confronted with a problem, think 'I know, I'll use regular expressions'..."
You know the rest.
Admin
Admin
All that and he still got it massively wrong.
Replacing + with an empty string is going to screw it up for any sort of international phonenumber of the +61234567890 format.
Admin
Please do not attempt to clean up any phone numbers! Either they match your pattern, or return them to the user for review, as there's probably a typo ... p.e. (JS):
Admin
That routine needs a rewrite! Not all unicode characters are properly replaced.
Admin
If you want to check if it's a number, sure that might work. Although I'm guessing that all languages will have a better method.
But that's not the goal. He's stripping out all the non-numeric characters. So '(020)-1234-5678' becomes '02012345678'. We don't care if the starting point isn't a number, we're trying to make it into one.
Admin
You must have a stranger javascript interpreter then as it replaces all of them for me... even gives you an example with more than one occurance on the W3C site. :S
Admin
hold up.... looks like i have the strange interpreter.... wtf?? it shouldnt work but does?? back to bed me thinks, try again tomorrow
Admin
Gads! It's a limited length string! Just walk the fscking thing! Even as a PL/SQL Function this is elementary.
Execute a toNumber() on each character and if the cast succeeds you keep the character. The exception trap just discards the character so you can proceed next.
A final viability check for length against known/acceptable dialed number formats and you're pretty much done.
Admin
TRWTF is so many people acting smart about fixing code that they read on a site about terrible code.
Look at me! I'm slightly more intelligent than a retard! I WIN!
Admin
In my math book, adding zero to (020)-1234-5678 (as suggested), yields -6892, not 02012345678!
Admin
Insanitisation shurely?
Admin
This is absolutely a lesson that should be taught to programming students: When you're filtering user inputs, a whitelist is pretty much always more secure than a blacklist.
Admin
I'd say walking the value is almost certainly the correct way of doing it. Using a regexp for this task is just stupid and inefficient.
Admin
Aren't bullshit anecdotes fun?
Admin
[quote user="blarg"]Are you one of those guys who spends 3 days finding a 'clever' workaround to save 2 clock cycles for a task which is called once an hour and has a disk/network bottleneck anyway?[/quote] No, I'm the sort of person who uses the right tool for the job. [/quote]
All evidence suggests otherwise if you think wasting time optimizing this is a worthwhile thing to do. Perhaps your time and your companies money is worth a lot less than mine, which explains why you would be happy to work on optimizations that have absolutely no noticeable benefit. Parsing a telephone number is a very different scenario to doing high frequency trading or low latency messaging etc - the right tool for the job is not going to be the same. Boog is completely right.
Admin
Not sure about that... he might have been running his "buy one line, get two lines free" promotion
Admin
You know the rest.
Admin
Admin
I'll just quote the post you obviously didn't bother reading:
But to be fair, I shouldn't have bothered with that Zawinski quote in the first place; I don't even agree with it.