- 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
2^56 = 72.057.594.037.927.936, no wonder the value of 72.057.594.038.400.000 caused problems...
Admin
Since well-reasoned, humorous and insightful first comment wasn't a valid option in the survey, I'll stick to the classic - FRIST!
Edit: well, almost
Admin
Just because you can doesn't mean you should. JUST BECAUSE YOU CAN DOESN'T MEAN YOU SHOULD.
:(
Admin
I think that's not the only problems I see... that number could in theory be the result of a few very specific publications being selected. More likely it's the result of floating point precision where they should have used int (or rather, shouldn't have used this hare-brained scheme at all).
CAPTCHA: burned
Admin
Indeed - PHP only stores integers natively for values which fit in a 32-bit signed value - once it goes higher, it starts using a high-precision floating point number instead. In most cases, the precision is high enough, but once it goes too high, well, this particular trick rather abruptly stops working; for example, if I run the code '$x = 72057594037927936; echo $x;' in Win32 PHP, the result is "7.20575940379E+16".
Admin
This is one of those WTF's where you almost have to be clever to come up with something this stupid.
Admin
Very clever. It might be a good idea if integers didn't have storage limits.....
Admin
Admin
Admin
Ah, but you did catch yourself, and that's the difference.
Admin
This would actually be a nice solution if the number of items stored was fixed and known to be a small number (e.g. less than 32 or so).
I shudder to think, though, what the INSERT statement would look like when you create a new publication record. If you had subqueries available it would be something like this:
INSERT INTO PUBLICATIONS NAME, VALUE VALUES ("Newspaper",2*(SELECT MAX VALUE FROM PUBLICATIONS));
If you didn't have subqueries available it would be even worse. You would think that typing out this kind of code would have caused somebody to think twice about what they were doing...then again you would probably know better than to trust the average developer's judgment.
Admin
Admin
Simple solution:
Charge the original programmer $0.01 for the first bug fix, $0.02 for the second, $0.04 for the third...
CAPTCHA: bathe. Ouch.
Admin
it's no problem you just need a bigger integer :)
Admin
Admin
The real WTF is that they were using MySQL - they are lucky that the database stored that large value without silently modifying it!
Admin
32 bits should be enough for anybody!
Admin
Yet another case of management unwilling to spend time on code reviews. Interns, Grunts, Jr. Developers, etc and the companies that employ them would all benefit greatly taking just an hour each week to review the work performed.
Is it really a WTF if the problem is so common?
Admin
For the first time in aeons, and actual WTF!
Admin
We have a stupid like this in our codebase. It's actually slightly combinatorial, but in that 'not really' sort of way.
Of the 64 possible values you will only ever have 2, 3 or 4. Not really viable.
We're on our 6th revision and it's still not gone away, mainly because it's in really vital sections and deleting it would break a lot of stuff.
Thankfully the original idiot who thought it was a good idea...moved on.
SQL hates bitmasks.
Admin
The ERP system we use stores, for example, order line item sequence numbers, as increasing powers of 2. It's always kind of made me a little uneasy that some day I might discover why it does this, and be horrified.
Admin
TRWTF is PHP
Admin
I was already cringing when I saw a column called "value" on a table called "publication". When you see a name as uninformative as that, you can just assume you're in trouble, before you even look at what it contains.
Admin
I see that both the Perl and the Postgres elitists have checked in. Too bad the story doesn't mention OS or we might have the "real WTF is using Windows" crowd.
Admin
Admin
Our coder paid too much attention in computer school. Like the sorcerer's apprentice, he learned how to invoke things he couldn't control.
I often surprised when a test for equality works. Data gets changed all the time behind the scenes.
Admin
Yeah, but what about the times he didn't and some poor guy coming along later had to maintain his code?
Admin
If the floating-point inaccuracies are at fault, I have a robust solution: change the column type to varchar(255)!
(please tell me that's not what they did...)
Admin
Admin
Newbie programmer here who doesn't really know what bitwise operations are. Could someone explain?
Admin
Your comment about PHP only demonstrates your own ignorance to what the language has become. The fact that there are rookie programmers in PHP is not a problem with the language—I've worked with far worse code in the other 20-someodd languages that I work with on a regular basis.
Also, some people have the regex stigma (it looks more difficult, therefore it's a bad idea) on bitmasks, which I don’t agree with at all. They’re a tool, just like anything else. In an environment with a constrained number of flags and where storage and database IO is at a premium, bitmasks can be an extremely efficient way of storing boolean values.
Just because some of the people on this thread don't understand the power of bitwise operations doesn't mean that they aren't the right choice when used correctly—it just means that you're all destined to make far worse WTFs because of your ignorance.
Admin
Missed the quote . . .
Your comment about PHP only demonstrates your own ignorance to what the language has become. The fact that there are rookie programmers in PHP is not a problem with the language—I've worked with far worse code in the other 20-someodd languages that I work with on a regular basis.
Also, some people have the regex stigma (it looks more difficult, therefore it's a bad idea) on bitmasks, which I don’t agree with at all. They’re a tool, just like anything else. In an environment with a constrained number of flags and where storage and database IO is at a premium, bitmasks can be an extremely efficient way of storing boolean values.
Just because some of the people on this thread don't understand the power of bitwise operations doesn't mean that they aren't the right choice when used correctly—it just means that you're all destined to make far worse WTFs because of your ignorance.
CAPTCHA: muhahaha (I think this site is mocking me)
Admin
http://en.wikipedia.org/wiki/Bitwise_operation
That pretty well covers it. For the purposes of today's WTF, however, you need only understand that bitshifting left grows a number exponentially and will very quickly overflow whatever datatype it's being stored in.
Admin
Re: bitwise operations
Integers are stored in binary. For instance, assuming 8-bit integers, 68 is 01000100 and 15 is 00001111. The & operator (bitwise AND) goes through two integers bit by bit and ANDs each but. Thus, in the example shown so far, 68 & 15 would be equal to 00000100 (4) since the 4 bit is the only bit enabled in both numbers.
Thus, an array of boolean values can be stored in a bit vector where each bit corresponds to a certain flag and the value of that setting can be extracted with a bitwise operation. For instance:
sampleInteger & 0x00000010 would return 2 (00000010) if the second bit of sampleInteger was enabled and 0 if it wasn't. Since in many modern programming languages 0 is false and anything else is true, you can simply use the syntax
if (sampleInteger & mask) to see if a flag is enabled.
CAPTCHA: sanitarium (I think an insanitarium would be more fun)
Admin
Hmm...question for the purists: Does the use of the value field this count as a violation of 1NF, which requires that the domain of each attribute include only atomic values? There's a structure implicit in a bitfield, but is that still said to apply when the accepted values have only one on-bit each? It's isomorphic to consecutive integers.
Admin
Bitwise operations compare numbers at the bit level. Think of each variable as an array of bits.
Bitwise AND: Bit-X-Result is 1 if and only if Bit-X-Operand1 AND Bit-X-Operand2 are 1
Bitwise OR: Bit-X-Result is 1 if and only if AT LEAST ONE OF Bit-X-Operand1 OR Bit-X-Operand2 is 1
Bitwise XOR: Bit-X-Result is 1 if and only if ONLY ONE OF Bit-X-Operand1 OR Bit-X-Operand 2 is 1.
He was using the sum of the values as an array of bits. That is, you could visualize the variable as a series of checkboxes for publications. So if the ordered, say, the WSJ and the Washington Post, youd get 10000010 (reading right-to-left, the "2" bit and the "128" bit are set).
The problem with this is that variables aren't really designed to be used this way. It can work if you have a very small number of bit-flags to set (see hardware architectures and error flags), and that number is exceedingly unlikely to change. But if you have a long list of publications that may change over time, you're in deep crap. Worse yet is if you can't guarantee how many bits you'll have (if you were coding this in C, you could typedef your value to a uint32_t, then later to a uint64_t, and not have to worry too much at first).
Admin
Well, in the current form the field is just a weird encoding for an enum, and therefore atomic. So no, I wouldn't count it as a 1NF violation.
Admin
I think this WTF defines quite nicely the term "Clever idiot."
I get the feeling this programmer read an article about bit-masks and forced the issue to apply the newfound knowledge. Unfortunately this is all too common. This type of situation is probably responsible for 2/3 of the XML usage in existence today.
Admin
well... i started about 8 months ago at this software firm, and to date i have fixed 289 bugs. it got absurd after about the 30th bug, but i wouldn't mind being able to buy a couple galaxies.
Admin
Only two WTFs I see here.
The first paragraph of the article; the rest is nothing but expected.
And the comments here trying to justify how this might be a valid approach given the right assumptions. The idea is stupid down to the lowest level. This sort of trick is only "clever" in any way, shape, or form if you're still a student learning language basics, not if you're actually writing professional code that will be expandable, readable, and maintainable.
It would be even worse if it did work, because it would embody the spirit of Worse Than Failure: shipping the code as a brilliant clever success not realizing you failed at good software development practices.
Admin
Good work, Paul!
Admin
This would actually be a nice solution if the number of items stored was fixed and known to be a small number (e.g. less than 32 or so).
Indeed I've used this method many times - when needing to store the status of a small number of flags. We have web services on an intranet where there are 'roles' defined per service type; there are never more than 5 or 6 roles. A given users' access privilege is stored as a single integer which is interpreted as bit flags. This method does have valid uses - obviously the case in this WTF is not one of them. In olden days when resources were limited storing info as bit flags was common.
Admin
Perl elitists?? Here? Yeah right. Mostly .NET and Java elitists around here as far as I can tell. Except for me, I'm a Ruby elitist. Didn't most of the Perl elitists drop out the web dev scene when CGI went out of fashion?
BTW, PHP sucks.
Admin
I love having to maintain code from someone who completely dropped out of the industry.
I've had to replace someone who decided he could make more money running a marijuana grow house and my boss had to drive to his house to pick up the dev server (the dev server being at his house is another WTF altogether) and the thing smelled like he had been smoking most of his crop.
I've also had to take over for a programmer who fled the country to find his "Muslim roots" in the Middle East. At least he was too lazy to do any major damage, although most of his code didn't work at all.
Admin
I like bitmaps as much as the next guy but perhaps you missed the point yourself.
This is one of the instances where a bitmask is a bad idea, that is why it is here on WTF.
Quite simply you can't effectively query things such as "Who is subscribed to the New York Times". Not saying it is impossible just saying it does not well match the index that the DB would build over a bit mapped field such as this.
Admin
It's a violation of relational database system design, because it uses an external coding of the data, rather than using the relational database system.
BTW, a good optimising RDBMS would store this index in a bitfield anyway, for small numbers of values, and would seamlessly handle the extension to many values when it was required.
Admin
I disagree in this case. The implicit casting from integer to float is evil. I much prefer the way of Python and Erlang where all integers have an arbitrary precision. The classic way of having a finite precision is fine too. But what PHP basically does is treating all numbers as floating point numbers and still have bitwise operations. Evil!
Admin
Irrelevant, if one uses MSSQL, which stores groups of bit (single boolean) fields together, anyway, internally. ie if you have 8 bit fields spread throughout your table, MSSQL will store them as a single byte, internally, rather than as a ton of separate bytes (just try writing less than a byte to disk - I dare you), wasting space. It seems insignificant, but it really is significant, in aggregate. If a table has, say, 12 bit fields, it would take up 2 bytes in MSSQL. In other systems, like MySQL, it would take up 12 bytes. Now fill that table to just 1 million records. That's around 2MB in MSSQL and 12MB in MySQL. I'll scan the smaller table, thank you.
Admin
Admin
...of course if you were doing that manually, then you'd have to know the values (SELECT name, value FROM publications), but obviously there'd be a script written to retrieve this info for you, where you simply select publications and it gives you a subscriber list.