- 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
Admin
Admin
Oh snap!
Admin
At the risk of being tautological, if you don't need to do math on the thing, it's not a number, it's just an identifier.
I'll add ISBNs and PINs to KattMan's list, and subclass part numbers as UPCs and EANs.
Admin
No matter how much I look at it, I will always see "crapola" as a combination of "crap" and "cola," and so I will always think of it as the flavor of Pepsi Blue. (Or Crystal Pepsi, if you prefer.)
Admin
A more pragmatic answer would be: "So you can preserve the puctuation and don't need extra code to remove it on input and add it on output", or "if you ever want to go international, note that some countries have numbers starting with 0".
Admin
Why did I read it in Georg Carlins voice?
Admin
Admin
No, dude. What you should have learned from that is that your suck as a coder, and that your logic is not quite there yet.
I'm referring to casting that phone number value to numeric. If you're casting to this and that solely on the look of the value, that's where you're making a mistake. Add a metadata value that will mean the type, and cast based on that.
Admin
Perl is also quite interesting with large integers:
#! /usr/bin/perl
printf "%d\n", 2 ** 62; #4611686018427387904 printf "%d\n", 2 ** 63; #-9223372036854775808 printf "%d\n", 2 ** 64; #-1
Admin
Reminds me of something I did once.
The purpose of the code was to read a barcode badge that contained a persons SSN and alert them to pending notices. Simple enough, but we needed to provide keyboard input because they may not have their badges just yet.
I thought I'd take a shortcut and just do a validation check by casting to a number and displaying an error if it didn't match. Well, it also happens that the barcodes append a number to the end depending on what department you work for (1 digit). Making the barcode numbers 10 digits long.
Well this all worked for testing, because every test badge we had used SSNs printed for people in PA (SSNs start with 1 most of the time). The first time a contractor arrived from out of state (about 1 day after this went live), he had an SSN / badge that started with a 3. Broke everything good.
Now we have real input validation!
Admin
Also, TRWTFIPHP
Admin
This isn't the worst I've seen. Here's how MS SQL Server guesses data types in imported Excel spreadsheets:
Thankfully, SQL Server does care about cell formatting (unlike Access, another program that has WTF Excel importing - you'd think Office would have pretty good compatibility with itself, but you'd be wrong). So if you format the column as Text, it won't type-guess.
But as an added bonus, it silently fails to import numeric values into fields set up as varchars. And there's no option to tell it to explicitly cast numbers to strings either. So you get to import the data once to get all of the numeric employee IDs, import it again to get the non-numeric ones, and then merge them together.
Edit: To be clear here - I mean that, even if it's from a column that you explicitly state is a string, SQL Server will still insist that "24593" is a number, and will fail to import it, presumably because it converts it from a string to a number, and then wonders why it can't put it into a string field.
Admin
You know what? After looking over Google results for 214-748-3647, it's obvious that there is some way to game Google to have your search turn up for anything that looks like a phone number. (Not that I hadn't already guessed this from all the crap you get when you type in anything vaguely like an electronic part number.)
According to the results I get, people all over the country have this number, not just in Dallas! I think I even saw an address from Ontario with this number.
Admin
Admin
That's because C is a low level language, without the concept of exceptions. You use it when you want a low level language, and don't want the computer to do things when you are not looking. If you are coding in C, you'd better know what comes from that addition, or at least check error.
That is different from PHP. You choose PHP when you must work on a PHP codebase, or when you are insane.
Admin
Admin
Too late on getting that phone number.
It was taken in the early 90's by a friend of mine.
He has going to an asterix box. It all goes to voice mail.
On occasion he listens and says that some of that is pretty funny. Mostly it is drunks guys who have just hit some crazy max score on the arcade game Golden Tee. They think it is a hoot to call the number and leave a message.
He should save some of those up and post them.... but that would be too much like work.... :)
Admin
Hey why are you spreading my phone number around?
Admin
Admin
Yet in many situations C sets errno, a rough approximation of an exception, e.g. if using strol(). Not here.
Admin
http://www.slashdot.org/
Dogs are animals that fear most stammering stealth but can't reproduce exotic beef jerky. Moira is a name that was given to some girl in a story and didn't have any meaning other than the meaning that it had. Candle-lit dinners are dark.
Evil isn't good.
What? The water? I can't hear it because the stand of Douglas Fir is rustling in the wind blown by large mountains falling in the sky to the area left of the wood burning farm for sticky bootlaces. I don't know.
http://www.yahoo.com/
Admin
Welcome to the wonderful world of PHP.
In the world of PHP, if you ask it to do something stupid that it doesn't understand, it decides that it's better to just do something rather than give you one of those troublesome error messages that stops your program from running. Nobody likes those.
Admin
Well a more useful comparison would be what dose atoi() do when given input to large for an integer. That too appears to be undefined so your point stands.
Still unlike C which needs to be simple to best meet many of its use cases, PHP is a high level language with a pretty specific target application. I would expect some error handling from its type conversion library functions.
Admin
Just ran into something similar.
Zip codes and social security numbers can start with a zero and look odd when stored as an int.
Admin
That seems rather pointless. If all the numbers start with a zero, then the zero is superfluous and could be left off.
Well, that said, my electric company has all it's customer account numbers start with the same three digits, I think it's 973 or some such. So when you call and they ask for your account number, if you give a number that DOESN'T start with 973, they know that you're giving them the wrong number so they don't try to use your phone number or social security number or whatever as an account number and maybe screw up someone else's account. Or if a customer has trouble finding their account number on their bill or whatever paperwork, they can say, "Look for a number that starts with 973." Seems like a not-bad idea; I may use it someday.
Admin
If you store ZIPCodes as numbers, you'll lose leading zeros and have to do a bunch of casting/converting/BS to get the right value.
ProTip: If humans use the word "number" in describing the data, it's never* really a number. VIN, Account Number, Customer Number, etc.
*close enough to be "never" to be truthy.
Admin
Well, I've been in this busy for 30 years, and I must admit that I didn't immediately recognize it. Sure, if you asked me what the 32 bit int max was, I would have said 2.1 something billion. But seeing it formatted as a phone number, it just didn't occur to me. I can see that if you live in or near a 214 area code, it would be even less likely to leap out.
Indeed, my first thought when I saw that phone number given was, Wow, shouldn't they have anonymized this, put in a 555 number or something? Otherwise a bunch of idiots are liable to call that number.
Admin
Veekun's the guy who designed the architecture that Facebook runs on, right?
No?
Admin
Apparently the poster isn't the only person to have a problem with this magic phone number.
http://www.24hourplaces.com/search.php?state=AL&city=&category=0&zip=&miles=1&page=1
Admin
As opposed to projects small enough that you don't need any language at all? I'm not sure what that means. "What language did you write this program in? Java? PHP? Visual Basic?" "No, this was a small project, so I didn't use a language."
But this is just a short comment, so instead of writing it in English or Spanish or French, I probably should have just written it without using a language.
Admin
Admin
Yes phone numbers are not numbers at all. You sometimes need extension numbers. Or maybe a + to indicate the first part is an international calling code.
If you are dealing with international phone numbers you will never be able to insert dashes programmatically. There are too many rules and they change too often. In South Korea, for example, the number of digits in the area code varies and the remaining part of the phone number may be 7 or 8 digits. By convention they split it up into 3 and 4 or 4 and 4.
Admin
TRWTF is using PHP for anything moderately complex.
Admin
I agree. How tough would it be to strip out spaces and hyphens so the user can enter his phone number or credit card number the way he is used to seeing it?
Back in the early days of computers (I don't think so much today), many people would type the letter oh instead of zero and the letter el instead of one, which of course would then screw up numeric inputs. Manuals would routinely lecture users not to do this. Just because it looks right on a typewriter, it doesn't work on the computer, etc.
My boss years ago came up with a simple solution: He modified our number input function to interpret letter oh as a zero and letter el as a one. When I saw it I thought, zounds, what a simple solution! Instead of lecturing users over and over about the same error, just fix it for them!
Admin
PHP can not be use for serious projects.
Admin
Great. So they can complacent on your application, then go entering invalid data in all the other applications.
I would rather use an input mask so they can mash the 0h and el keys all they want but they will not pass validation because they have not typed enough characters. Eventually maybe they will get a clue and find the 0 and 1 keys actually show up on screen.
Admin
Admin
Admin
Also, you could use alpha-numeric in phone number for aliases 1-800-WTF-WTF1
Admin
Dude, next time treat phone number as strings, why in hell would you treat differently.
Noob mistake.. i hope you have learn!
Admin
I inlined your correction in the above quote...
What you're seeing here is a bunch of quirks of the C language and what compilers are allowed to do.
First off, when I compile this, I get a warning for the INT_MAX+1 expression. So any developer should immediately know something's wrong here.
The reason for the seemingly contradictory answers is that the compiler isn't actually doing any arithmetic, but is shortcutting the expression, generating constants.
In the case of the first expression ((INT_MAX+1) > INT_MAX), the compiler knows that you've generated an overflow (producing the warning.) It also knows that on the x86 platform, INT_MAX+1 is INT_MIN. So the comparison returns false. The generated code passes a 0 constant to printf.
In the case of the second expression (in the function foo), it sees the expression ((x+1)>x), which is true for all values of x other than INT_MAX. Since INT_MAX+1 is an implementation-defined expression, it can optimize the whole expression to a constant. The generated code passes a 1 constant to printf.
Some interesting observations (in playing with this):
1: If you change the parameter to foo (x) to (volatile int x) then the compiler will make no attempt to optimize the expression. It will do the addition, the result will wrap to INT_MIN, and the function will return 0.
2: If you replace the expression INT_MAX+1 with the result (2147483648), then the compiler will replace the int constant with a long constant, eliminating the warning and causing the constant 1 to be passed to printf, because there's no more overflow condition. (explicitly Casting INT_MAX to long will do the same thing.)
Admin
I'd hate to be the guy in Dallas trying to start up a business placing guard animals, only to discover the alternative significance of 714-PIT-DOGS.
Admin
I pity the person (according to a quick search: Wil Stuart) in the Dallas area who actually HAS the number (214)748-3647. Someone else mentioned that he has a recorder on the number. So, let's all try it (not really, he doesn't need the attention!).
Before (like before 1995) when ALL area codes had a 1 or a 0 as the middle digit, you COULD actually encode a US/Canada phone number as a 32 bit int. Take the middle digit of the area code as the most significant digit and then use the next 9 digits. Some things actually used this technique. Now with the proliferation of things like cell phones (which chew up LOTS of phone numbers) we have zads of area codes, so it doesn't work any more. In this encoding scheme, the phone number would be encoded as: 1247483647. Trivia: When AT&T first proposed things like area codes back in the 1940's, they estimated that the scheme with area codes with 1 or 0 as the middle digit would last until around 2000, considering that they were estimating 50 years in the future, being off by 10% (5 years) was a pretty good prediction.
Admin
ANOTHER integer overflow WTF, don't the editors ever get tired of them? Anyone who can't immediately recognize an integer limit value shouldn't be reading this site anyway.
Admin
All I learned from this is that your code is shit.
And there's probably 10 submissions that weren't posted here about how you were casting the number and it broke that stupid language spectacularly.
Admin
Well, any actual comment spam kinda has to have a link to work. And a lot of comment spam tends to be drawn from other comments, with a link thrown in. It's probably a pretty effective heuristic.
Admin
"I don't see C receiving the same level of disrespect as PHP."
Experienced programmers realize that C is a glorified assembler language, so they expect it to do things like this. A high-level [sic] language like PHP should offer more protection.
Admin
Admin
(although, TBH I've never worked anywhere where the Dev box is exactly the same as the prod box - partly because people have played with config, partly because the box is often lower spec and partly because people are scared that if they make it too real it might accidentally do real stuff)